Reputation: 65
I am trying to convert a UNIX timestamp into iso8601 format.
for ex:
UNIX timestamp "1483050457000"
how do I convert it to iso8601 time format in ruby ??
Upvotes: 2
Views: 1542
Reputation: 110755
require 'time'
Time.at("1483050457000".to_i).iso8601
#=> "48965-12-30T12:16:40-08:00"
require 'time'
is essential here. Without it you find that you only have access to Time
's core methods. Run Time.instance_methods.sort
to list them. By first executing require 'time'
the following instance methods are added to the class Time
: => [:httpdate, :iso8601, :rfc2822, :rfc822, :to_date, :to_datetime, :to_time, :xmlschema]
.
Upvotes: 3
Reputation: 10696
You seem to be getting your epoch time stamp in the form of a string, so the following will probably be easiest for you:
DateTime.strptime("1483050457000",'%s')
Note: You seem to have supplied an invalid time stamp in your question, otherwise, I'd have included the output. Try that code with a valid time stamp, and you should get what you want.
Upvotes: 2