🐍 Python - datetime
Updated at 2018-11-19 19:07
datetime
module is the Python way to handle dates and times.
from datetime import timedelta, datetime, timezone
print(datetime(2018, 11, 1, 23, 59))
# 2018-11-01 23:59:00
print(timedelta(hours=1))
# 1:00:00
print(datetime.now(timezone.utc))
# 2018-11-14 11:32:20.181024+00:00
print(datetime.now(timezone.utc) + timedelta(hours=1))
# 2018-11-14 12:32:20.181401+00:00
print(datetime.now(timezone.utc).isoformat())
# 2018-11-14T11:32:20.181424+00:00
iso_format = '%Y-%m-%dT%H:%M:%S.%f%z'
print(datetime.strptime('2018-11-14T11:32:20.181424+00:00', iso_format))
# 2018-11-14 11:32:20.181424+00:00