Iván Cortés Romero Iván Cortés Romero - 2 years ago 128
Ruby Question

yyyy-mm-ddThh:mm:ss.000Z date format in Ruby

I am consuming an API which returns a date like this

. This format is new for me, so, What is the name of this date format? and, how can I treat it in Ruby?

Answer Source

That's an ISO 8601 date and DateTime.parse has no trouble parsing it:

require "date"

str = "2016-05-05T20:59:31.000Z"
p DateTime.parse(str)
# => #<DateTime: 2016-05-05T20:59:31+00:00 ((2457514j,75571s,0n),+0s,2299161j)>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download