Partially Attended

an irregularly updated blog by Ian Mulvany

blog posts about time

Converting between dates and unix time in Python

Going from a date to a unix time: >>> from datetime import date >>> from time import mktime >>> start = date(2011, 9, 26) >>> mktime(start.timetuple()) 1316991600.0 Going from a unix time to a date: >>> from time import strftime >>> from datetime import datetime >>> datetime.fromtimestamp(int("1284101485")).strftime('%Y-%m-%d%H:%M:%S') '2010-09-10 07:51:25' ... (more)