[sf-lug] unix time conversion

Charles-Henri Gros chgros at coverity.com
Mon Oct 27 16:07:50 PDT 2008


> Got it!
> 
> Now that you have wetted my appetite:
> How to change a human readable time into 'unix time?'
> (preferably using python so this becomes applicable to the ThinkPython grp)
> 
>>>> string = "July 3, 1945"
>>>> import time
>>>> time(string)
> 
> the above doesn't work but is it just because the format of the date is incorrect or is there a bigger problem?

Unfortunately, parsing a human-readable date is much harder than
generating one.
time() is not a parsing function (it just returns the current time in
epoch seconds)

Python apparently has a time parsing function, strptime (presumably
based on the posix one), but I wasn't able to make it work.

It's definitely not a beginner kind of problem.

-- 
Charles-Henri




More information about the sf-lug mailing list