[英]Turning ruby string into datetime
Is it possible to turn 7/1/13 16:37 into a proper ruby DateTime object? 是否可以将7/1/13 16:37转换为适当的红宝石DateTime对象? Time.new and Time.parse seem to return the wrong thing... Time.new和Time.parse似乎返回了错误的信息...
Time.parse("7/1/13 16:37")
=> 2007-01-13 16:37:00 -0500
你可以使用strptime功能,检查这出。
Try using DateTime.parse(...)
: 尝试使用DateTime.parse(...)
:
require 'time'
x = DateTime.parse("7/1/13 16:37")
x.class # => DateTime
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.