簡體   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