change the date string into timestamp

John Ridley ojokimu at yahoo.co.uk
Sat Apr 9 09:14:58 EDT 2005


> praba kar wrote:
> 
> > In Php strtotime() will change a date
> > string into timestamp.  I want to know which 
> > python function will  change a date string
> > into timestamp.
> 

To convert a date-string *to* a timestamp (as you asked):

>>> import time, calendar
>>> date_string = time.strftime('%c', time.gmtime(1112952134))
>>> print date_string
Fri Apr  8 09:22:14 2005
>>> calendar.timegm(time.strptime(date_string))
1112952134


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 



More information about the Python-list mailing list