Converting UTC timestamp to ISO 8601 in Ruby

前端 未结 4 2071
礼貌的吻别
礼貌的吻别 2020-12-24 04:36

I have a timestamp that is in UTC

\"2010-10-25 23:48:46 UTC\"

I need to convert it into ISO 8601

\"2010-10-29 06:09Z\"

The documentation is

4条回答
  •  无人及你
    2020-12-24 05:02

    After much experimenting, I find the Time library's parser to be better than DateTime, although the reasons escape me at the moment. With that caveat, I always use Time rather than DateTime for this kind of stuff, and the ruby documentation is also difficult to grok as to why this is so,

    require 'time'
    puts Time.parse("2010-10-25 23:48:46 UTC").iso8601
    "2010-10-25T23:48:46Z"
    

提交回复
热议问题