Python: TIME module

/ Published in: Python
Save to your folder(s)

Copy this code and paste it in your HTML
  1. ## 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.
  3. ##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.
  4. >>>print time.time()
  5. 1155333864.11
  7. ##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:
  8. >>>print time.localtime()
  9. (2006, 8, 11, 16, 4, 24, 4, 223, 1)
  11. ##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:
  12. >>>print time.ctime()
  13. Fri Aug 11 16:04:24 2006
  15. ##The time.clock() function returns the current CPU time as a floating-point number that can be used for various timing functions:
  16. >>>print time.clock()
  17. 5.02857206712e-006
  19. ##The time.sleep(sec) function forces the current process to sleep for the number of seconds specified by the floating-point number secs:
  20. >>>time.sleep(.5)

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.