Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the utc offset in Rails?

I need the utc offset from the timezone specified.

like image 676
Lucas Renan Avatar asked Mar 30 '11 14:03

Lucas Renan


People also ask

How do I get timezone offset?

Definition and Usage. getTimezoneOffset() returns the difference between UTC time and local time. getTimezoneOffset() returns the difference in minutes. For example, if your time zone is GMT+2, -120 will be returned.

How do I get timezone from UTC offset?

Timezone offset is the time difference in hours or minutes between the Coordinated Universal Time (UTC) and a given time zone. The JavaScript getTimezoneOffset() method is used to find the timezone offset. It returns the timezone difference in minutes, between the UTC and the current local time.

How do you use UTC offset?

(GMT-5:00) Eastern Time (US & Canada)Add the local time offset to the UTC time. For example, if your local time offset is -5:00, and if the UTC time is shown as 11:00, add -5 to 11. The time setting when adjusted for offset is 06:00 (6:00 A.M.). Note The date also follows UTC format.

What is base UTC offset?

The BaseUtcOffset property returns the difference between UTC and the time zone's standard time; the GetUtcOffset method returns the difference between UTC and the time zone's time at a particular point in time.


1 Answers

If you need to take daylight savings time into account, you can use something like this:

Time.now.in_time_zone('America/New_York').utc_offset 
like image 130
lee Avatar answered Sep 22 '22 13:09

lee