I'm here on Ubuntu 12.04, and I can see:
$ cat /etc/timezone
America/Phoenix
Accordingly Time
will return a time with a non-UTC zone:
$ irb
> Time.now
=> 2013-03-27 13:44:49 -0700
> Time.at 0
=> 1969-12-31 17:00:00 -0700
I can override the system time zone using the TZ
environment variable:
$ TZ=UTC irb
> Time.now
=> 2013-03-27 20:47:19 +0000
> Time.at 0
=> 1970-01-01 00:00:00 +0000
Is there anyway I can make this change programmatically, within a Ruby process?
You store separate environment variables in config/development. rb , config/testing. rb and config/production. rb respectively.
You can also set environment variables from within ruby by accessing the ENV
hash:
ENV['TZ'] = 'UTC'
Time.at 0
#=> 1970-01-01 00:00:00 +0000
also see this answer: Set time zone offset in Ruby, It provides a way to write something like
with_time_zone 'UTC' do
# do stuff
end
# now TZ is reset to system standard
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