Some of the time-related packages and functions are most used and later used to supplement
Import datetime Import Time # Gets the current period, which contains year, month, hour, which requires import datetime today = Datetime.date.today () print (Toda
Y) print (today.year) print (today.month) print (today.day) ' >>>2017-01-01 >>>2017 >>>1 >>>1 ' ' # to get tomorrow, and the other in turn tomorrow = Today + Datetime.timedelta (Days=1) print (Tomorrow) ' >>>2017-01-0
2 ' ' # time subtracted, adding empathy now = Datetime.timedelta (days=0, hours=0, minutes=3, seconds=50);
Pre = Datetime.timedelta (days=0, hours=0, Minutes=1, seconds=10); Duration_sec = (now-pre). Seconds Duration_day = (now-pre). Days Print (Type (duration_sec)) print (Type (now-pre)) print (
DURATION_SEC) print (duration_day) ' >>><class ' int ' > >>><class ' Datetime.timedelta ' > >>>160 >>>0 ' ' # uses time.strftime (format, p_tuple) to get the current time, which requires import times now = Time.strftime ("%h:%m:%s" Print (now) ' ' >>>23:49:34 ' # using DateTime.Now () now = Datetime.datetime.now () print (now) print (now.year) PRI NT (now. Month) print (now.day) print (now.hour) print (now.minute) print (now.second) print (now.microsecond) ' >>>
2017-01-01 23:49:34.789292 >>>2017 >>>1 >>>1 >>>23 >>>49 >>>34 >>>789292 ' "
Document Address: Datetime-basic Date and time types