Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get UTC timestamp in Ruby?

Tags:

timestamp

ruby

How to get UTC timestamp in Ruby?

like image 707
Mohit Jain Avatar asked May 31 '10 11:05

Mohit Jain


People also ask

How do I get UTC time in Ruby?

Time Zones You can check the current time zone for a Time object using the zone method. This will give you the time zone abbreviation. If you want the time zone offset you can use the utc_offset method. The output for this method is in seconds, but you can divide by 3600 to get it in hours.

How do I find my UTC timestamp?

Use the getTime() method to get a UTC timestamp, e.g. new Date(). getTime() . The method returns the number of milliseconds since the Unix Epoch and always uses UTC for time representation. Calling the method from any time zone returns the same UTC timestamp.

What is the UTC timestamp?

The abbreviation UTC stands for Coordinated Universal Time or Temps Universal Coordonné and denotes the time, derived from atomic time, valid all over the world. This uses the 24-hour clock and the Gregorian Calendar as its standard.

Is timestamp stored in UTC?

For timestamp with time zone, the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone.


1 Answers

You could use: Time.now.to_i.

like image 135
manzhikov Avatar answered Sep 24 '22 08:09

manzhikov