I would recommend installing an excellent dateutil module. (On Ubuntu / Debian, it is provided by the python-dateutil package).
dateutil can parse date strings in datetime objects: it can handle many different date formats without having to lift a finger (*):
import dateutil.parser as dparser
date=dparser.parse("Mon May 7 1883 10:36:28")
print(date)
date=dparser.parse("1685-3-21")
print(date)
date=dparser.parse("12/17/1770")
print(date)
, "12/17/1770" "MM/DD/YYYY". , parse dayfirst yearfirst. (. http://labix.org/python-dateutil)
print(type(date))
datetime :
dates=[dparser.parse("Mon May 7 1883 10:36:28"),dparser.parse("1685-3-21"),dparser.parse("12/17/1770"),]
dates.sort()
print(dates)
dateutil,
datetime. , . "% Y-% m-% d" YYYY-MM-DD. . http://au2.php.net/strftime ( strftime) .
,
dates=[datetime.datetime.strptime(date_str,'%Y-%m-%d') for date_str in
('1883-5-7','1685-3-21','1770-12-17',)]
print([str(date) for date in dates])
dates.sort()
print([str(date) for date in dates])
datetime , datetime.datetime.strftime().