hken27
hken27

Reputation: 413

Date time parse or time class?

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

Answers (1)

Hunter McMillen
Hunter McMillen

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

Related Questions