import datetime
t = datetime.datetime(2012, 2, 23, 0, 0)
t.strftime('%m/%d/%Y')
from datetime import datetime
datetime_object = datetime.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p')
from datetime import datetime, timezone
timestamp_str = str(datetime.now(timezone.utc))
print(timestamp_str, type(timestamp_str)) # 2022-05-06 11:23:00.718012+00:00 <class 'str'>
timestamp = datetime.fromisoformat(timestamp_str) # Python 3.7+:
print(timestamp, type(timestamp)) # 2022-05-06 11:23:00.718012+00:00 <class 'datetime.datetime'>
timestamp = datetime.strptime(timestamp_str, '%Y-%m-%d %H:%M:%S.%f%z')
print(timestamp, type(timestamp)) # 2022-05-06 11:23:00.718012+00:00 <class 'datetime.datetime'>
# import the datetime module
import datetime
# datetime in string format for may 25 1999
input = '2021/05/25'
# format
format = '%Y/%m/%d'
# convert from string format to datetime format
datetime = datetime.datetime.strptime(input, format)
# get the date from the datetime using date()
# function
print(datetime.date())
# Python program to demonstrate datetime object
# import datetime class
from datetime import datetime as date
# Getting current date and time
now = date.now()
string = date.isoformat(now)
print(string)
print(type(string))