# Time class and time zones

**URL:** <https://www.ruby-forum.com/t/time-class-and-time-zones/60529>\
**Category:** Ruby\
**Created:** [May 15, 2006, 10:40am UTC](https://www.ruby-forum.com/t/time-class-and-time-zones/60529 "2006-05-15T10:40:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![edlau](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@edlau](https://www.ruby-forum.com/u/edlau)\
**Post date:** [May 15, 2006, 10:40am UTC](https://www.ruby-forum.com/t/time-class-and-time-zones/60529/1 "2006-05-15T10:40:33Z")

</div>

Question in brief:  
Is it possible to create a Time object with a time zone other than the  
local time zone or GMT?

I’m relatively new to Ruby (coming from the Java world), and after  
reading the docs and playing with Time a fair bit, I’ve decided that you  
can’t create a Time object with an arbitrary time zone. Is this correct?

For example, let’s say my local time zone is PDT (GMT-8). Can I create a  
Time object representing 16:00 EDT (GMT-5) in New York? Sure, I know I  
can represent that time as 13:00 PDT or 21:00 GMT, but that’s not what I  
want to do.

I’m writing an app that deals with user time zones across the globe. If  
I normalize my users’ times to local or GMT, I lose information. I.e., I  
would like my app to remember times exactly as it was input–if a time  
was input as Eastern Time (US), it should be displayed as Eastern Time  
upon retrieval. Can I store the time zone datum in the Time object, or  
must I persist an addition time zone field along with the Time object?  
The downside to keeping track of the time zone externally is that I  
can’t take advantage of Time’s format method and it just seems kludgy in  
general.

I’d appreciate any feedback. Perhaps I’m going about this the wrong way.  
Thanks much!

–Ed Lau

---

<div class="post-metadata">

**Author:** ![edlau](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@edlau](https://www.ruby-forum.com/u/edlau)\
**Post date:** [May 15, 2006, 11:08am UTC](https://www.ruby-forum.com/t/time-class-and-time-zones/60529/2 "2006-05-15T11:08:07Z")

</div>

Ed Lau wrote:

> Question in brief:  
> Is it possible to create a Time object with a time zone other than the  
> local time zone or GMT?

Slightly tangential to your question, but they might lead to  
some ideas:

[http://redhanded.hobix.com/inspect/showingPerfectTime.html](http://redhanded.hobix.com/inspect/showingPerfectTime.html)  
[http://redhanded.hobix.com/bits/showingPerfectTimePerfectPlusEdition.html](http://redhanded.hobix.com/bits/showingPerfectTimePerfectPlusEdition.html)

Regards,

---

<div class="post-metadata">

**Author:** ![edlau](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@edlau](https://www.ruby-forum.com/u/edlau)\
**Post date:** [May 15, 2006, 4:43pm UTC](https://www.ruby-forum.com/t/time-class-and-time-zones/60529/3 "2006-05-15T16:43:13Z")

</div>

Check out [http://tzinfo.rubyforge.org/](http://tzinfo.rubyforge.org/)

TZInfo is a Ruby library that uses the standard tz (Olson) database to  
provide daylight savings aware transformations between times in  
different  
time zones. The tz database is compiled into Ruby classes which are  
packaged in the release. No external zoneinfo files are required at  
runtime.

All the best  
JE

---

<div class="post-metadata">

**Author:** ![edlau](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@edlau](https://www.ruby-forum.com/u/edlau)\
**Post date:** [May 16, 2006, 6:36am UTC](https://www.ruby-forum.com/t/time-class-and-time-zones/60529/4 "2006-05-16T06:36:19Z")

</div>

Quoting removed\_email\_address@domain.invalid, on Mon, May 15, 2006 at 11:40:18PM +0900:

> Check out [http://tzinfo.rubyforge.org/](http://tzinfo.rubyforge.org/)
> 
> TZInfo is a Ruby library that uses the standard tz (Olson) database to  
> provide daylight savings aware transformations between times in different  
> time zones. The tz database is compiled into Ruby classes which are  
> packaged in the release. No external zoneinfo files are required at  
> runtime.

Hey, thats great! I’ve wanted to make vPim timezone-aware for a while,  
but haven’t had the energy. It looks like it won’t be too hard with  
this.

Thanks,  
Sam
