[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Timezone?

Guillaume Loader

2/18/2009 10:33:00 PM

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!
--
Posted via http://www.ruby-....

3 Answers

Chris Shea

2/18/2009 11:17:00 PM

0

On Feb 18, 3:33 pm, Guillaume Loader <picpi...@hotmail.com> wrote:
> 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!
> --
> Posted viahttp://www.ruby-....

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.ht...

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

Guillaume Loader

2/18/2009 11:29:00 PM

0

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

--
Posted via http://www.ruby-....

Guillaume Loader

2/19/2009 1:58:00 AM

0

Thanks for the reply! I got it!
--
Posted via http://www.ruby-....