1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| from datetime import date
date(2022, 2, 3)
from datetime import time
time(5, 35, 2)
from datetime import datetime
datetime(2000, 2, 3, 5, 35, 2)
now = datetime.now() print (now)
today = date.today() print (today)
time(now.hour, now.minute, now.second)
now.isocalendar()
week_number = now.isocalendar()[1] print (week_number)
date.fromisoformat("2022-12-31")
date(2022, 12, 31).isoformat()
iso_date = "2022-12-31 23:59:58"
iso_format = "%Y-%m-%d %H:%M:%S"
datetime.strptime(iso_date, iso_format)
datetime_obj = datetime(2022, 12, 31)
american_format = "%m-%d-%Y"
european_format = "%d-%m-%Y"
print(f"American date string: {datetime.strftime(datetime_obj, american_format)}.")
print(f"European date string: {datetime.strftime(datetime_obj, european_format)}.")
new_year_2023 = datetime(2022, 12, 31) datetime.timestamp(new_year_2023) datetime.fromtimestamp(1672441200)
|