Operations by time:
1. time () : — this function is used to count the number of seconds since the beginning of an epoch .
2. gmtime (sec) : — this function returns a structure with 9 values, each of which is a temporary attribute in a sequence. It converts seconds to time attributes (days, years, months, etc.) Until the specified seconds from the beginning of the epoch. If no seconds are specified, the time is calculated up to the present time. The structure attribute table is shown below.
Index Attributes Values 0 tm_year 2008 1 tm_mon 1 to 12 2 tm_mday 1 to 31 3 tm_hour 0 to 23 4 tm_min 0 to 59 5 tm_sec 0 to 61 (60 or 61 are leap -seconds) 6 tm_wday 0 to 6 7 tm_yday 1 to 366 8 tm_isdst -1, 0, 1 where -1 means Library determines DST
Seconds elapsed since the epoch are: 1470121951.9536893 Time calculated acc. to given seconds is: time.struct_time (tm_year = 2016, tm_mon = 8, tm_mday = 2, tm_hour = 7, tm_min = 12, tm_sec = 31, tm_wday = 1, tm_yday = 215, tm_isdst = 0)
3.asctime : — this function takes a string with a time attribute, generated by gmtime (), and returns a string of 24 characters for the time .
4.ctime (sec) : — this function returns a 24-character temporary string, but takes seconds as an argument and calculates the time until the specified seconds . If no argument is passed, time is calculated to date.
Time calculated using asctime () is: Tue Aug 2 07:47:02 2016 Time calculated using ctime () is: Tue Aug 2 07:47:02 2016
5. sleep (sec) : — This method is used to track program execution over the time specified in the arguments.
Start Execution: Tue Aug 2 07:59:03 2016 Stop Execution: Tue Aug 2 07:59:07 2016
This article courtesy of Manjeet Singh . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.