How to get UTC timestamp 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.
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.
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.
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.
You could use: Time.now.to_i
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With