How do I Convert DateTime.now to UTC in Ruby?

前端 未结 7 1527
既然无缘
既然无缘 2020-12-01 04:24

If I have d = DateTime.now, how do I convert \'d\' into UTC (with the appropriate date)?

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 04:34

    The string representation of a DateTime can be parsed by the Time class.

    > Time.parse(DateTime.now.to_s).utc
    => 2015-10-06 14:53:51 UTC
    

提交回复
热议问题