# DateTime in Linux

**URL:** <https://www.ruby-forum.com/t/datetime-in-linux/152264>\
**Category:** Rails\
**Created:** [November 1, 2008, 12:12am UTC](https://www.ruby-forum.com/t/datetime-in-linux/152264 "2008-11-01T00:12:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 1, 2008, 12:12am UTC](https://www.ruby-forum.com/t/datetime-in-linux/152264/1 "2008-11-01T00:12:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 1, 2008, 12:21am UTC](https://www.ruby-forum.com/t/datetime-in-linux/152264/2 "2008-11-01T00:21:15Z")

</div>

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 Z.  
Zapient, LLC  
Ruby on Rails Development and Consulting

[http://www.zapient.com](http://www.zapient.com)

> **[From Java To Ruby](http://www.fromjavatoruby.com)**
>
> and everything in between...

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 1, 2008, 12:41am UTC](https://www.ruby-forum.com/t/datetime-in-linux/152264/3 "2008-11-01T00:41:08Z")

</div>

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.

\*\*

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 5, 2008, 7:05am UTC](https://www.ruby-forum.com/t/datetime-in-linux/152264/4 "2008-11-05T07:05:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 3, 2008, 8:47pm UTC](https://www.ruby-forum.com/t/datetime-in-linux/152264/5 "2008-11-03T20:47:18Z")

</div>

Try this.

> > evt.start\_time.in\_time\_zone(‘Arizona’)

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

–  
Robert Z.  
Zapient, LLC  
Ruby on Rails Development and Consulting

[http://www.zapient.com](http://www.zapient.com)

> **[From Java To Ruby](http://www.fromjavatoruby.com)**
>
> and everything in between...
