string = "02/27/2014 08:01:11"
DateTime.parse(string) # failed
和
DateTime.strptime(string) # failed
(string).to_datetime # failed
我还在顶部包含了这些内容:
require 'date'
require 'active_support/core_ext/string/conversions'
答案 0 :(得分:2)
使用Date::strptime
方法:
require 'date'
s = "02/27/2014 08:01:11"
Date.strptime(s,"%m/%d/%Y %H:%M:%S")
# => #<Date: 2014-02-27 ((2456716j,0s,0n),+0s,2299161j)>