1 #examples of time module functions2 Import Time3 4 #gets the current time stamp5t =time.time ()6 Print('gets the current timestamp:', T)7 8 #struct_time form of the current time9t =time.localtime ()Ten Print('the Struct_time form of the current time:', T) One Print('Current Year:', T.tm_year) A - #the string form of the current time -t =time.ctime () the Print('the string form of the current time:', T) - - #string of the current time custom format -t = time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ()) + Print('string for the current time custom format:', T)
Operation Result:
1 Get current timestamp: 1501808069.95581722 struct_time form of current time: Time.struct_time (tm_year=2017, tm_mon=8, tm_ Mday=43 tm_hour=8, tm_min=54, tm_sec=294 tm_wday=4, tm_yday=216, tm_ isdst=0)5 Current year:6 string form of current time: Fri 4 08:54:297 Current time custom formatted string: 2017-08-04 08:54:29
Python Time module