1import datetime
2date = '2021-05-21 11:22:03'
3datem = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
4print(datem.day) # 25
5print(datem.month) # 5
6print(datem.year) # 2021
7print(datem.hour) # 11
8print(datem.minute) # 22
9print(datem.second) # 3
1import datetime
2dt = datetime.datetime.today()
3year = dt.year
4month = dt.month
5day = dt.day
1>>> import datetime
2>>> today = datetime.datetime.now()
3>>> print today
42009-03-06 15:37:02.484000
5>>> today.strftime('%j')
6'065'
1from datetime import datetime
2
3day_of_year = datetime.now().timetuple().tm_yday