Skip to content

Instantly share code, notes, and snippets.

@lxneng
Created March 15, 2010 16:17
Show Gist options
  • Save lxneng/332994 to your computer and use it in GitHub Desktop.
Save lxneng/332994 to your computer and use it in GitHub Desktop.
#http://docs.python.org/library/time.html#time.strptime
time.strptime('Sat Mar 20', '%a %b %d')
time.struct_time(tm_year=1900, tm_mon=3, tm_mday=20, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=79, tm_isdst=-1)
time.strptime('3pm', '%I%p')
time.struct_time(tm_year=1900, tm_mon=1, tm_mday=1, tm_hour=15, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=1, tm_isdst=-1)
In [19]: dts = 'Sat Mar 20 2010 5pm'
In [20]: time.strptime(dts,'%a %b %d %Y %I%p')
Out[20]: time.struct_time(tm_year=2010, tm_mon=3, tm_mday=20, tm_hour=17, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=79, tm_isdst=-1)
In [26]: time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(dts,'%a %b %d %Y %I%p'))
Out[26]: '2010-03-20 17:00:00'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment