hyperrjas
hyperrjas

Reputation: 10744

Datetime to utc format

I have this DateTime format:

var1 = 2014-06-10T18:49:59+00:00

and I want convert to this format:

var2 = 2014-06-10 18:49:59 UTC

Thanks!

Upvotes: 1

Views: 4303

Answers (2)

Erez Rabih
Erez Rabih

Reputation: 15788

Try:

Time.parse(var1.to_s).utc

Assuming var1 holds a DateTime object.

Upvotes: 3

mcfinnigan
mcfinnigan

Reputation: 11638

Use strftime:

var2 = var1.strftime("%Y-%m-%d %H:%M:%S %z")

see the strftime documentation for more format strings

http://www.ruby-doc.org/core-2.0/Time.html

Upvotes: 0

Related Questions