[Tutor] Processing unix style timestamp
John Fouhy
john at fouhy.net
Fri Mar 7 01:20:36 CET 2008
On 07/03/2008, Ravi Kondamuru <ravikondamuru at gmail.com> wrote:
> I have a log file that prints the date and time in the following format:
> Mon Feb 11 01:34:52 CST 2008
> I am expecting multiple timezone entries (eg: PST, PDT and GMT) on the
> system running in America/Los Angeles time zone.
> I am looking for a way to internally store all the different timezone
> entries in GMT.
> I looked at datetime, but it seems slightly complex to work with non GMT
> timestamps.
Maybe you could split out the information.. e.g.:
>>> s = 'Mon Feb 11 01:34:52 CST 2008'
>>> s[4:19] + s[23:], s[20:23]
('Feb 11 01:34:52 2008', 'CST')
You should be able to parse the former with strptime(). You could
then build a dictionary mapping timezones to offsets which you could
add to the parsed time to produce a time in GMT.
--
John.
More information about the Tutor
mailing list