I'm trying to get the UTC offset for a datetime. The datetime is saved as:
Fri, 31 May 2013 15:19:08 EDT -04:00
What I'd like to get is "-04:00"
. When I do object.utc_offset
, I get -14400
. What function should I use?
You are looking for strftime
:
Time.now.strftime("%:z")
That will give you the offset such as "-04:00".
Its in seconds. Divide by 3600 for hours, or 60 for minutes.
But if you want the formatted offset string, use vgoff's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With