# Timezone?

**URL:** <https://www.ruby-forum.com/t/timezone/160697>\
**Category:** Ruby\
**Created:** [February 18, 2009, 11:33pm UTC](https://www.ruby-forum.com/t/timezone/160697 "2009-02-18T23:33:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![loader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/5daacb/32.png) [@loader](https://www.ruby-forum.com/u/loader)\
**Post date:** [February 18, 2009, 11:33pm UTC](https://www.ruby-forum.com/t/timezone/160697/1 "2009-02-18T23:33:23Z")

</div>

Hello everyone!

I have a question 🙂

When I run this command :  
puts Time.now  
I got =\> 2009-02-18T14:31:17-08:00

But if then I do this :  
require ‘date’; expiration\_date = DateTime.new(2008, 02, 18, 12, 12,  
13); puts expiration\_date  
I got =\> 2008-02-18T12:12:13+00:00

My question is : What is the “-08:00” ? I assume it’s the timezone? Then  
how to set my expiration\_date variable to have the same timezone?

Thank you!

---

<div class="post-metadata">

**Author:** ![loader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/5daacb/32.png) [@loader](https://www.ruby-forum.com/u/loader)\
**Post date:** [February 19, 2009, 12:29am UTC](https://www.ruby-forum.com/t/timezone/160697/2 "2009-02-19T00:29:36Z")

</div>

Perfect!  
By the waym why -8/24.0 instead of -8/24 ?  
Thank you!

---

<div class="post-metadata">

**Author:** ![loader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/5daacb/32.png) [@loader](https://www.ruby-forum.com/u/loader)\
**Post date:** [February 19, 2009, 12:20am UTC](https://www.ruby-forum.com/t/timezone/160697/3 "2009-02-19T00:20:42Z")

</div>

On Feb 18, 3:33 pm, Guillaume L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 13); puts expiration\_date  
> I got =\> 2008-02-18T12:12:13+00:00
> 
> My question is : What is the “-08:00” ? I assume it’s the timezone? Then  
> how to set my expiration\_date variable to have the same timezone?
> 
> ## Thank you!
> 
> Posted viahttp://www.ruby-forum.com/.

DateTime.new is an alias for DateTime.civil. You can see its  
documentation here:  
[http://www.ruby-doc.org/stdlib/libdoc/date/rdoc/classes/DateTime.html#M000400](http://www.ruby-doc.org/stdlib/libdoc/date/rdoc/classes/DateTime.html#M000400)

You’re right that “-08:00” is something like a timezone. It’s the  
offset from UTC (Coordinated Universal Time) and it’s determined by  
your timezone. Anyway, as you can see in the documentation, there’s  
an extra argument after the one for seconds where you can set your  
offset. It’s set as a fraction of a day, so in your case you’d want  
to do something like this:

expiration\_date = DateTime.new(2008, 02, 18, 12, 12, 13, -8/24.0)

HTH,  
Chris

---

<div class="post-metadata">

**Author:** ![loader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/5daacb/32.png) [@loader](https://www.ruby-forum.com/u/loader)\
**Post date:** [February 19, 2009, 2:57am UTC](https://www.ruby-forum.com/t/timezone/160697/4 "2009-02-19T02:57:41Z")

</div>

Thanks for the reply! I got it!

---

<div class="post-metadata">

**Author:** ![loader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/5daacb/32.png) [@loader](https://www.ruby-forum.com/u/loader)\
**Post date:** [February 19, 2009, 12:53am UTC](https://www.ruby-forum.com/t/timezone/160697/5 "2009-02-19T00:53:30Z")

</div>

On [Thu, 19.02.2009 08:29], Guillaume L. wrote:

> By the waym why -8/24.0 instead of -8/24 ?  
> Fire up an instance of irb and see for yourself.  
> Nah: if you did -8/24 it would return -1 instead of -0.33~  
> That’s because arithmethic operations always return a value as precise  
> as the precisest one in the term, which in this case is an Integer, no  
> floating point number.
