我正在尝试使用Datetime.strptime解析指纹识别器的xml文件但是时间是12小时没有填充,似乎没有strftime选项来读取它。我尝试了%-I,但它没有用。
来自API
Time (Hour, Minute, Second, Subsecond):
%H - Hour of the day, 24-hour clock, zero-padded (00..23)
%k - Hour of the day, 24-hour clock, blank-padded ( 0..23)
%I - Hour of the day, 12-hour clock, zero-padded (01..12)
%l - Hour of the day, 12-hour clock, blank-padded ( 1..12)
xml数据包的片段
<ROW Pin="142" Name="142" sTime="8/12/2013 8:14 PM" VerifyFlag="Fingerpint" MachineName="Office" Abnormite=""/>
<ROW Pin="163" Name="163" sTime="8/12/2013 8:16 PM" VerifyFlag="Fingerpint" MachineName="Office" Abnormite=""/>
<ROW Pin="103" Name="103" sTime="8/13/2013 12:03 AM" VerifyFlag="Fingerpint" MachineName="Office" Abnormite=""/>
<ROW Pin="101" Name="101" sTime="8/13/2013 12:03 AM" VerifyFlag="Fingerpint" MachineName="Office" Abnormite=""/>
<ROW Pin="401" Name="401" sTime="8/13/2013 12:36 AM" VerifyFlag="Fingerpint" MachineName="Office" Abnormite=""/>
<ROW Pin="505" Name="505" sTime="8/13/2013 2:17 AM" VerifyFlag="Fingerpint" MachineName="Office" Abnormite=""/>
答案 0 :(得分:1)
使用%l
选项似乎解析得很好。
凌晨2:17
> DateTime.strptime("8/13/2013 2:17 AM", "%m/%d/%Y %l:%M %p")
=> Tue, 13 Aug 2013 02:17:00 +0000
下午2:17
> DateTime.strptime("8/13/2013 2:17 PM", "%m/%d/%Y %l:%M %p")
=> Tue, 13 Aug 2013 14:17:00 +0000