Python strptime or alternative for complex date string parsing -


i have been given large list of date-time representations need read database. using python (because rocks). strings in terrible, terrible format not precise seconds, no timezone stated, , hours not have leading 0. more this:

april 29, 2013, 7:52 p.m. april 30, 2013, 4 p.m. 

you'll notice if happens between 4:00 , 4:01 drops minutes, (ugh). anyway, trying parse these time.strptime, the docs state hours must decimal numbers [01:12] (or [01:24]). since nothing padded 0's i'm wondering if there else can pass strptime accept hours without leading 0; or if should try splitting, padding strings; or use other method of constructing datetime object.

also, not strptime accepts am/pm "a.m." or "p.m.", i'll have correct well. . .

note, not able handle these strings in batch. receive them one-at-a-time foreign application uses nicely formatted unix epoch timestamps, uses format. processing them on fly option.

i using python 2.7 python 3 features imported.

from __future__ import (print_function, unicode_literals) 

the flexible parser part of dateutil package; eats input breakfast:

>>> dateutil import parser >>> parser.parse('april 29, 2013, 7:52 p.m.') datetime.datetime(2013, 4, 29, 19, 52) >>> parser.parse('april 30, 2013, 4 p.m.') datetime.datetime(2013, 4, 30, 16, 0) 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -