Skip to content

Instantly share code, notes, and snippets.

@lambdamusic
Created February 7, 2013 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambdamusic/4734389 to your computer and use it in GitHub Desktop.
Save lambdamusic/4734389 to your computer and use it in GitHub Desktop.
Python: Python: TIME module
## 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment