Am Samstag, 9. April 2005 11:38 schrieb praba kar: > In Php strtotime() will change a date > string into timestamp. I want to know which > python function will change a date string > into timestamp.
You want the standard library function strptime from the time module (in case it's a timestamp you're looking for), otherwise have a look at the library documentation for the datetime module, which gives you a datetime class which can also be constructed strptime-like from a string. Example: >>> date = "Fri, 8 Apr 2005 09:22:14 +0900" >>> timetuple = time.strptime(date,"%a, %d %b %Y %H:%M:%S +0900") >>> timetuple (2005, 4, 8, 9, 22, 14, 4, 98, -1) >>> timestamp = time.mktime(timetuple) >>> timestamp 1112944934.0 The timestamp is in local time, as is the timetuple (I've hardcoded the +0900, there's no format string which will parse the timezone parameter, and recode the time to UTC, it's up to you to do that). -- --- Heiko. listening to: Pearl Jam - Spin The Black Circle see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/
pgpAlMVOkrzJS.pgp
Description: PGP signature
-- http://mail.python.org/mailman/listinfo/python-list