strptime
String to datetime object =
strptime
datetime object to other formats =
strftime
Jun 1 2005 1:33PM
is equals to %b %d %Y %I:%M%p
%b - Month as locale’s abbreviated name(Jun)Use slicing to remove unwanted characters if necessary.
%d - Day of the month as a zero-padded decimal number(1)
%Y - Year with century as a decimal number(2015)
%I - Hour (12-hour clock) as a zero-padded decimal number(01)
%M - Minute as a zero-padded decimal number(33)
%p - Locale’s equivalent of either AM or PM(PM)
Example :
>>> import time
>>> time.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p')
time.struct_time(tm_year=2005, tm_mon=6, tm_mday=1,
tm_hour=13, tm_min=33, tm_sec=0,
tm_wday=2, tm_yday=152, tm_isdst=-1)