在Ruby中,如何在没有时区的情况下创建UTC DateTime?

发布于 2025-02-12 04:41:07 字数 262 浏览 0 评论 0原文

我有以下代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蘸点软妹酱 2025-02-19 04:41:07

将最后一行更改为:

puts utc.strftime('%F %T')

对于以后的类似问题,请参阅DateTime strftime方法的文档:

https://ruby-doc.org/stdlib/libdoc/date/rdoc/rdoc/datetime.html#method-i-i-i-strtftime

Change the last line to:

puts utc.strftime('%F %T')

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文