strtotime?

Peter Hansen peter at engcorp.com
Thu Jan 22 19:10:40 EST 2004


Leif K-Brooks wrote:
> 
> Irmen de Jong wrote:
> >> PHP has a very nice strtotime function (http://php.net/strtotime)
> >> which converts a date/time in virtually any format into a timestamp.
> >> Does Python have a similar function?
> >
> > I guess you're looking for:  time.strptime
> 
> Thanks, but no. PHP's strtotime() function magically guesses the format
> on its own, time.strptime() just uses a fixed format.

Perhaps the mx.DateTime package would help:

>From http://www.lemburg.com/files/python/mxDateTime.html:
------------------------------
DateTimeFrom(*args,**kws) 

Constructs a DateTime instance from the arguments. 

This constructor can parse strings, handle numeric arguments and knows about 
the keywords year,month,day,hour,minute,second.  

It uses type inference to find out how to interpret the arguments and makes 
use of the Parser module. 
------------------------------

-Peter



More information about the Python-list mailing list