Nick ONeill Nick ONeill - 6 months ago 10
Ruby Question

How do you get the local timezone offset in "+hh:mm" format?

I know how to get the current utc_offset using

Time.current.utc_offset
but how can I get it in the format "+hh:mm"?

The best solution I have so far is
DateTime.now.to_s[-6,6]

Answer

strftime with %z (: means hour and minute offset from UTC with a colon):

Time.current.strftime("%:z")
Comments