How do I change the zone offset for a time in Ruby on Rails? -


I have a variable foo that has a time, say at 4 o'clock, but the field offset is wrong, that is it Wrong time zone How do I change the time zone?

When I print it I

  Fri Jun 26 07:00:00 UTC 2009  

Then there is no offset , And I would like to set Offset to -4 or the Eastern Standard Time.

I just want to be able to set offset the property of the time object, but is not it available?

You can not explicitly say how you get actual variables but since you have time class I think you get the time to use it and I will tell it in my answer

Time zone is actually part of the time class (in your case the timezone showed as UTC has gone). Time. Now as part of the time, the offset will return from UTC. Respond now.

  & gt; & Gt; Local = time.Now => 2012-08-13 08:36:50 +0000 & gt; & Gt; Local.hour = & gt; 8 & gt; & Gt; Local.min = & gt; 36 & gt; & Gt;  


... in this case I have to be in the same time zone as GMT

Changing between timezones

The easiest way to get it is to change the offset to getlocal method using the '+/- HH: MM' format. Let's pretend I want to change time between Dublin and New York in time

 ? & Gt; Dublin = Time.nu = & gt; 2012-08-13 08:36:50 +0000 & gt; & Gt; New_york = Dublin + Time.Jon_Offetset ('EST') = & gt; 2012-08-13 08:36:50 +0000 & gt; & Gt; Dublin.hour = & gt; 8 & gt; & Gt; New_york.hour = & gt; 3 / << code> 

Assuming that 'EST' is the name of timezone for New York, as Dan has sometimes called 'ADT' as the right TZ.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -