How to parse this timestamp?

Miki miki.tebeka at gmail.com
Wed Mar 12 18:30:48 EDT 2008


Hello,

> [19-Aug-2007 07:38:43+216ms NZST]
>
> How can I parse them?  I don't see any way to build a strftime()
> format string that can handle the +216ms part. The best I can see is
> tearing it all apart with a regex, but I'm trying to avoid that pain
> if I can.
>
> (PS: I have no clue why google groups thinks it should put
> "gnu.gcc.help" on the from line)
Just zap the end and use time.strptime:
>>> s = '19-Aug-2007 07:38:43+216ms NZST'
>>> strptime(re.sub("\+\d{3}ms [A-Z]{4}", "", s), "%d-%b-%Y %H:%M:%S")
(2007, 8, 19, 7, 38, 43, 6, 231, -1)
>>>

HTH,
--
Miki <miki.tebeka at gmail.com>
http://pythonwise.blogspot.com



More information about the Python-list mailing list