How can I convert a tick, such as 1298011537289
to a DateTime in Ruby?
The value I need to convert is coming from a JavaScript Date.now()
call, so it's in milliseconds
How can I convert a tick, such as 1298011537289
to a DateTime in Ruby?
The value I need to convert is coming from a JavaScript Date.now()
call, so it's in milliseconds
Per the Ruby docs:
or since you're using milliseconds rather than seconds:
But that will only remove sub-second precision, to retain it:
Use strptime and parse it with the format
%Q - Number of microseconds since 1970-01-01 00:00:00 UTC.
Example:
DateTime.strptime "1352748750274", "%Q"
Assuming the value is in milliseconds, this is how I'd do it: