DateTime in Linux

1 view
Skip to first unread message

Charles

unread,
Oct 31, 2008, 6:17:36 PM10/31/08
to Ruby on Rails: Talk
I'm new to Ruby and have been pulling my hair out trying to figure out
an issue with displaying DateTime fields. I have programmed a very
simple app in Windows with a MySQL 5 database. The DateTime fields
appear to be saved in a UTC format. When displaying DateTime
information with the following -

<%=h evt.start_time.to_time %>

I see the following output (on Windows)

2008-10-31 03:00:00 -0700

In the database the value of the start_time field is - 2008-10-31
10:00:00. It appears "evt.start_time.to_time" is displaying DateTime
in localtime (MST).

However, the same code on my LINUX (CentOS 5) box yields the following
output -

2008-10-31 10:00:00 UTC

What am I missing? I've verified time, timezone and NTP settings on
the LINUX box.

I have the following setup in my environment.rb -

config.time_zone = 'Arizona'

I'm at a complete loss. Any help would be greatly appreciated.

C

Robert Zotter

unread,
Oct 31, 2008, 7:20:29 PM10/31/08
to Ruby on Rails: Talk
Charles,

I am not sure what you want to accomplish. If you want to display the
time you have listed in your database you can always use the
following.

<%= h evt.start_time.to_s(:db) %>

Is this what you are looking for?
--
Robert Zotter
Zapient, LLC
Ruby on Rails Development and Consulting

http://www.zapient.com
http://www.fromjavatoruby.com

Pete Barnes

unread,
Oct 31, 2008, 7:40:07 PM10/31/08
to rubyonra...@googlegroups.com
Robert,

I think what I need to do is convert a DateTime value. stored in the MYSQL db, of 2008-10-31 21:00:00 (UTC) to 2008-10-31 14:00:00 -0700 (AZ time).

Cheers.

Robert Zotter

unread,
Nov 3, 2008, 2:46:36 PM11/3/08
to Ruby on Rails: Talk
Try this.

>> evt.start_time.in_time_zone('Arizona')

Check out http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Zones.html.
And http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html
lists all the available timezones.

--
Robert Zotter
Zapient, LLC
Ruby on Rails Development and Consulting

http://www.zapient.com
http://www.fromjavatoruby.com

On Oct 31, 3:40 pm, "Pete Barnes" <scazzyhall1...@gmail.com> wrote:
> Robert,
>
> I think what I need to do is convert a DateTime value. stored in the MYSQL
> db, of 2008-10-31 21:00:00 (UTC) to 2008-10-31 14:00:00 -0700 (AZ time).
>
> Cheers.
>
> **

Pete Barnes

unread,
Nov 5, 2008, 1:04:47 AM11/5/08
to rubyonra...@googlegroups.com
I already tried that mate! No joy. 

Now this ruby script is the Java equivalent of an application - not rendered through a browser. Does that make a difference? This is list of my gems -

*** LOCAL GEMS ***

actionmailer (2.1.1, 2.1.0)
actionpack (2.1.1, 2.1.0)
activerecord (2.1.1, 2.1.0)
activeresource (2.1.1, 2.1.0)
activesupport (2.1.1, 2.1.0)
cgi_multipart_eof_fix (2.5.0)
daemons (1.0.10)
fastthread (1.0.1)
gem_plugin (0.2.3)
jicksta-adhearsion (0.7.999)
log4r (1.0.5)
mbleigh-subdomain-fu (0.0.2)
mongrel (1.1.5)
mysql (2.7)
rails (2.1.1, 2.1.0)
rake (0.8.2, 0.8.1)
rspec (1.1.4)
rubigen (1.3.2)

I'm using a MYSQL 5.0.45 for a the database. The field is defined as a DateTime.

This is the line of code that I can not get into localtime -

start_time = evt.start_time.in_time_zone('Arizona')

DB value : 2008-11-17 15:00:00

However, the same line of code on a web portal displays the correct localtime.

On my portal page : Monday Nov 17 8am

In my ruby app. the value of start_time is : 2008-11-17 15:00:00 -0700

Not very helpful!

Many thanks for your kind assistance.

C.
Reply all
Reply to author
Forward
0 new messages