Time

The time module

  • A variety of time related functions
     time.clock()           # Current CPU time in seconds
     time.time()            # Current time (GMT) in seconds since epoch
     time.localtime(secs)   # Convert time to local time (returns a tuple).
     time.gmtime(secs)      # Convert time to GMT (returns a tuple)
     time.asctime(tuple)    # Creates a string representing the time
     time.ctime(secs)       # Create a string representing local time
     time.mktime(tuple)     # Convert time tuple to seconds
     time.sleep(secs)       # Go to sleep for awhile
     

Example

     import time
     t = time.time()
     # Returns (year,month,day,hour,minute,second,weekday,day,dst)
     tp = time.localtime(t)
     # Produces a string like 'Mon Jul 12 14:45:23 1999'
     print time.localtime(tp)
     
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 60
July 17, 2000, beazley@cs.uchicago.edu
>>>