In Python, there are usually several ways to represent time:
- Timestamp (timestamp): The timestamp represents the offset that is calculated in seconds, starting January 1, 1970 00:00:00. We run "type (Time.time ())" and return the float type.
- Formatted time string (format string)
- Structured time (Struct_time): Struct_time A total of 9 elements in total nine elements: (year, month, day, hour, minute, second, week of the year, Day of the year, summer Time)
Between them can be converted
Time.localtime () If you do not add seconds, the default is T Ime.time () tuple , &N Bsp time.localtime default can not fill in
time.gmtime () UTC time &N Bsp tuples , &NB Sp , &NB Sp time.strftime ("%y-%m-%d%x", Time.localtime ()) string
Timestamp ----------------------------------------> & nbsp: Structured time ------------------------------------- > format time <--------------------------------------- , &NB Sp <--------------------------------------
Time.mktime () floating point time.strptime (' 2011-05-05 1 6:37:06 ', '%y-%m-%d%x ') tuples
both structural and timestamp can be converted to ' Sun June 20 23:21:05 1993 ' In this form of string.
Parameter structure asctime ([t]) if there are no parameters, the Time.localtime () will be passed in as a parameter
When the parameter timestamp ctime ([secs]) is none, the default Time.time () is the argument.
DateTime module
1 #time plus minus2 Importdatetime3 4 #print (Datetime.datetime.now ()) #返回 2016-08-19 12:47:03.9419255 #Print (Datetime.date.fromtimestamp (Time.time ())) # Timestamp goes directly to the date format 2016-08-196 #print (Datetime.datetime.now ())7 #print (Datetime.datetime.now () + Datetime.timedelta (3)) #当前时间 + 3 days8 #print (Datetime.datetime.now () + Datetime.timedelta ( -3)) #当前时间-3 days9 #print (Datetime.datetime.now () + Datetime.timedelta (hours=3)) #当前时间 + 3 hoursTen #print (Datetime.datetime.now () + Datetime.timedelta (minutes=30)) #当前时间 +30 points One A - # - #c_time = Datetime.datetime.now () the #Print (C_time.replace (minute=3,hour=2)) #时间替换 - -DateTime module
Learning Tour of Python ——— time module