Reputation: 413
This is for Ruby
Need help understanding Time.parse. I want the output to be "2011-01-02 11:00:00"
but I am getting "2011-01-02 11:00:00 -0800" with the following code. Any ideas?
require 'time'
def measure
Time.parse("2011-1-2 11:00:00")
end
Upvotes: 0
Views: 44
Reputation: 61540
It is just printing the number of hours your timezone is off UTC. You can use Time#strftime
to extract only the fields you are interested in
def measure
t = Time.parse("2011-1-2 11:00:00")
t.strftime "%Y-%m-%d %H:%M:%S"
end
# irb(main):037:0> measure
# => "2011-01-02 11:00:00"
Upvotes: 1