繁体   English   中英

strptime - 无效的日期错误

[英]strptime — Invalid Date Error

这应该是超级简单的,但我很难过:

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')

谢谢!

似乎strptimestrftime之间有一点区别。 我觉得你不需要-strptime

test_date = '2/20/2012 6:46:00 PM'
last_login = DateTime.strptime(test_date, '%m/%d/%Y %l:%M:%S %p')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM