Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]

like image 717
Nick ONeill Avatar asked Dec 10 '22 16:12

Nick ONeill


1 Answers

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

Time.current.strftime("%:z")
like image 193
James Chen Avatar answered Jan 17 '23 10:01

James Chen