The default time zone offset in Ruby is apparently -0800. I want to set mine to -0500. How do I do this?
You can do: Time. now + Time. zone_offset("PST") if you: require 'time' in your ruby script. guess, should have done that before commenting.
Ruby | DateTime parse() function DateTime#parse() : parse() is a DateTime class method which parses the given representation of date and time, and creates a DateTime object. Return: given representation of date and time, and creates a DateTime object.
The now() is an inbuilt method in Ruby returns the current time.
Set the TZ environment variable...
$ ruby -e 'puts Time.now' Sat Jan 15 20:49:10 -0800 2011 $ TZ=UTC ruby -e 'puts Time.now' Sun Jan 16 04:49:20 +0000 2011
Ruby gets the time zone information from the host's operating system.
Most directly, it uses a C library API specified by C99 and Posix.
The implementation of that API is system-specific, on my Mac that means it consults /etc/localtime
unless there is a TZ environment variable.
It's about the same on Linux.
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