孙悟空
孙悟空

Reputation: 1285

How to get timezone offset from Time.now

Time.now   #=> 2007-11-19 08:27:30 -0600

I want get timezone offset +0600 from Time.now. A Native ruby function is welcome if it exist.

What i tried :

Time.now.to_s.byteslice(-5..-1) #=> "-0600" as String

It works for my timezone(GET+1) but I want to find a better way.

Upvotes: 2

Views: 599

Answers (1)

Argonus
Argonus

Reputation: 1035

You can use it

Time.now.strftime('%z')

Upvotes: 5

Related Questions