datetime 和date 使用上类似
1 import datetime 2 print(datetime.datetime.today())#当前时间,到毫秒,datetime 类型 2018-01-23 21:55:43.756948 3 now = datetime.datetime.now()#和today()一样,datetime 类型 4 print(now) #2018-01-23 21:55:43.756948 5 print(now.year) #2018 6 print(now.month) #1 7 print(now.day) #23 8 print(now.hour)#21 9 print(now.minute)#55 10 print(now.second)#43 11 print(now.microsecond)#756947 12 print(datetime.datetime.today().strftime(‘%Y-%m-%d‘)) #2018-01-23,格式化时间 13 print(datetime.datetime.today() + datetime.timedelta(-3)) #3天前,datetime 类型 2018-01-20 21:55:43.756948 14 print(datetime.datetime.today() + datetime.timedelta(3)) #3天后,datetime 类型 2018-01-26 21:55:43.756948 15 print(datetime.date.today()) #2018-01-23 , <class ‘datetime.date‘>