将String转换为DateTime [英] convert String to DateTime
本文介绍了将String转换为DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将以下String解析为DateTime对象:
30 / Nov / 2009:16:29:30 +0100
I need to parse following String into a DateTime Object:
30/Nov/2009:16:29:30 +0100
有没有办法做到这一点?
Is there an easy way to do this?
PS:我想转换字符串上面是。一年后的冒号不是打字错误。我也想解决Ruby的问题,而不是RoR。
PS: I want to convert the string above as is. The colon after the year is not a typo. I also want to solve the problem with Ruby and not RoR.
推荐答案
DateTime.strptime 允许您指定格式并将String转换为DateTime。
DateTime.strptime allows you to specify the format and convert a String to a DateTime.
这篇关于将String转换为DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文