datetime
provides date and time calculations. import datetime date_str = '1970-08-28 22:23:24' dt = datetime.datetime.strptime(date_str, '%Y-%m-%d %H:%M:%S') print (dt.strftime('%H:%M:%S %d.%m.%Y'))
strptime
and the Perl module DateTime::Format::Strptime
. datetime.toordinal(…)
returns the number of days since December 31, 1 BC at 00:00 in the proleptic Gregorian date: import datetime print(datetime.datetime.strptime('0001-01-01', '%Y-%m-%d').toordinal()) # 1 print(datetime.datetime.strptime('1582-10-04', '%Y-%m-%d').toordinal()) # 577725 print(datetime.datetime.strptime('1582-10-05', '%Y-%m-%d').toordinal()) # 577726 - inexisting date print(datetime.datetime.strptime('1582-10-06', '%Y-%m-%d').toordinal()) # 577727 - inexisting date print(datetime.datetime.strptime('1582-10-15', '%Y-%m-%d').toordinal()) # 577736 - 1st gregorian day
import datetime; birthday_ = datetime.date(2014, 8, 28) print ("Birthday: " + birthday_.strftime("%Y-%m-%d")) # today_ = datetime.date.today() in_a_week_ = today_ + datetime.timedelta(days = 7) print ("The date in a week will be " + in_a_week_.strftime("%Y-%m-%d"))
import datetime; today_ = datetime.date.today() tomorrow_ = today_ + datetime.timedelta(days = 1) print ("The date in a week will be " + tomorrow_.strftime("%Y-%m-%d"))
dateutil
provides extensions to datetime
.