Return to Snippet

Revision: 21853
at December 22, 2009 15:20 by magicrebirth


Initial Code
## The time module provides a portable interface to time functions on the system on which the program is executing. The following examples illustrate some of the most common uses of the time module.

##The time.time() function returns the current system time in terms of the number of seconds since the UTC (Coordinated Universal Time). This value is typically collected at various points in the program and is used in delta operations to determine the amount of time since an event occurred.
>>>print time.time()
1155333864.11

##The time.localtime(secs) function returns the time, specified by secs since the UTC, in the form of tuple (year, month, day, hour, minute, second, day of week, day of year, daylight savings). If no time is specified, the current time is used as follows:
>>>print time.localtime()
(2006, 8, 11, 16, 4, 24, 4, 223, 1)

##The time.ctime(secs) function returns the time, specified by secs since the UTC, as a formatted, printable string. If no time is specified, then the current time is used as shown here:
>>>print time.ctime()
Fri Aug 11 16:04:24 2006

##The time.clock() function returns the current CPU time as a floating-point number that can be used for various timing functions:
>>>print time.clock()
5.02857206712e-006

##The time.sleep(sec) function forces the current process to sleep for the number of seconds specified by the floating-point number secs:
>>>time.sleep(.5)

Initial URL

                                

Initial Description

                                

Initial Title
Python: TIME module

Initial Tags
python

Initial Language
Python