Reputation: 81
I want to use Time.now.strftime("%d/%m/%Y %H:%M")
to show the current time in my timezone, but it seems to be delayed for two hours. It shows: 28/08/2017 06:36
when it is 08:36
. How can I adjust the timezone to show the right time?
Upvotes: 0
Views: 120
Reputation: 10251
Pure Ruby Way:
> Time.now.utc.localtime("+05:30").strftime("%d/%m/%Y %H:%M")
#=> "28/08/2017 12:41"
where +05:30
(IST) is the offset of the particular zone
Note: Time.now.getlocal.zone
will return your local zone
Using ActiveSupport:
> require 'active_support/time'
#=> true
> Time.now.in_time_zone('US/Eastern').strftime("%d/%m/%Y %H:%M")
#=> "28/08/2017 03:17"
Upvotes: 5