The time module can be used to format dates and times , which are floating-point decimals in seconds. Each timestamp is represented by how long it has been since midnight on January 1, 1970 (the calendar).
The following are some of the time-format conversion functions that are commonly used by times modules. Timestamps can be compared directly to size.
1 Import Time2 3 #If you want to convert time stamps and formatted time to each other, you must first turn into a time tuple before you can turn4 Print(Int (time.time ()))#Current time stamp5 cur_time = Time.strftime ('%y-%m-%d%h:%m:%s ')6Cur_time = Time.strftime ('%h%m%s')#format time to take the current time7Cur_time1 = Time.strftime ('%y-%m-%d')8 print (cur_time1)9 Ten Print(Type (cur_time1)) One Print(Time.gmtime ())#The default is the time tuple of the standard time zone, and if a timestamp is passed, the timestamp is converted to a time tuple. A Print(Time.timezone)#a few hours apart from the standard time. - Print(Time.gmtime (1516005840))#Standard Time zone. -Cur_time= Time.localtime (1516005840)#The default is to take the time tuple of the current time zone, and if a timestamp is passed, the timestamp is converted to a time tuple. theres = Time.strftime ('%y-%m-%d%h:%m:%s', Cur_time) - defTimestamptostr (time_strmp,format='%y%m%d%h%m%s'): - #time stamp to format good time -Cur_time = Time.localtime (TIME_STRMP)#time stamp into a time tuple +res = time.strftime (format, cur_time)#and then turn the time tuple into a well-formatted time. - returnRes + defStrtotimestamp (time_st,format='%y%m%d%h%m%s'): A #20181128113859 at #This function is a well-formed time, a time-stamped -T=time.strptime (Time_st,format)#turn formatted time into a time tuple -res = Time.mktime (t)#time-tuple into timestamp - returnRes - -t = Timestamptostr (Time.time (),'%y-%m-%d') in Print(t) -T1 = Strtotimestamp (t,format='%y-%m-%d') to Print(t1) + Print(Type (t1)) - #86400 * 3 #3天 the #32342-86400 * 3 #3天前
Python Time module