日期时间解析未按预期工作
我的 Ruby 代码看起来有点像这样。
str = 2010-12-02_12-10-26
puts str
puts DateTime.parse(str, "%Y-%m-%d_%H-%M-%S")
我希望从解析中获得实际时间。相反,我得到这样的输出...
2010-12-02_12-10-26
2010-12-02T00:00:00+00:00
我如何也解析时间?
I have Ruby code that looks vaguely like this.
str = 2010-12-02_12-10-26
puts str
puts DateTime.parse(str, "%Y-%m-%d_%H-%M-%S")
I expected to get the actual time from the parse. Instead, I'm getting output like this...
2010-12-02_12-10-26
2010-12-02T00:00:00+00:00
How do I get the time parsed in as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有效:
此示例位于 Codepad 上。
根据文档
解析
:和strptime:
This works:
This example on Codepad.
According to the documentation
parse
:And
strptime
:使用 strptime 而不是 parse
Use strptime instead of parse