user1455140
user1455140

Reputation: 35

Convert Date Time to UTC in Ruby

I want to display the date and time in the following format

Sat, Jul 07, 2012 19:28:06 UTC

I haven't been able to find a conversion method that leaves the UTC at the end.

I am currently using the following

t = Time.now.utc.strftime("%a, %B %d, %Y %H:%M:%S %Z")

However this displays the following

Sat, Jul 07, 2012 19:28:06 GMT

I want to see UTC not GMT at the end.

Upvotes: 2

Views: 1694

Answers (1)

Darshan Rivka Whittle
Darshan Rivka Whittle

Reputation: 34031

According to the Time documentation:

The Time class treats GMT (Greenwich Mean Time) and UTC (Coordinated Universal Time) as equivalent.

My system shows "UTC" at the end when running your code. For whatever reason, your system prefers the "GMT" moniker. Since this is just cosmetic, you can use:

Time.now.utc.strftime("%a, %B %d, %Y %H:%M:%S UTC")

Upvotes: 1

Related Questions