3

这应该非常简单,但我很难过:

require 'time'
# works fine, prints "2/20/2012 6:46:00 PM"
puts Time.new(2012,2,20,18,46,0).strftime('%-m/%-d/%Y %-l:%M:%S %p')
test_date = '2/20/2012 6:46:00 PM'
# Invalid date error -- why??
# What am I doing wrong in my usage of strptime?
last_login = DateTime.strptime(test_date, '%-m/%-d/%Y %-l:%M:%S %p')

谢谢!

4

1 回答 1

6

strptime和之间似乎有一点区别strftime。我认为你不需要-strptime.

test_date = '2/20/2012 6:46:00 PM'
last_login = DateTime.strptime(test_date, '%m/%d/%Y %l:%M:%S %p')
于 2012-10-29T03:14:17.430 回答