在Ruby中,如何在没有时区的情况下创建UTC DateTime?
我有以下代码:
require 'time'
utc = DateTime.parse("2019-01-01 00:00:00", "yyyy-mm-dd hh:mm:ss")
puts utc
输出2019-01-01T00:00:00+00:00
。如何将其设置为格式2019-01-01 00:00:00
?
I have the below code:
require 'time'
utc = DateTime.parse("2019-01-01 00:00:00", "yyyy-mm-dd hh:mm:ss")
puts utc
which outputs 2019-01-01T00:00:00+00:00
. How can I get this to be in the format 2019-01-01 00:00:00
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将最后一行更改为:
对于以后的类似问题,请参阅DateTime strftime方法的文档:
https://ruby-doc.org/stdlib/libdoc/date/rdoc/rdoc/datetime.html#method-i-i-i-strtftime
Change the last line to:
For similar questions in the future, refer to the documentation of DateTime's strftime method:
https://ruby-doc.org/stdlib/libdoc/date/rdoc/DateTime.html#method-i-strftime