
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
The time Module in Python
There is a popular time module available in Python which provides functions for working with times and for converting between representations. Here is the list of all available methods −
Sr.No | Function with Description |
---|---|
1 | time.altzone The offset of the local DST timezone, in seconds west of UTC, if one is defined. This is negative if the local DST timezone is east of UTC (as in Western Europe, including the UK). Only use this if daylight is nonzero. |
2 | time.asctime([tupletime]) Accepts a time-tuple and returns a readable 24-character string such as 'Tue Dec 11 18:07:14 2008'. |
3 | time.clock( ) Returns the current CPU time as a floating-point number of seconds. To measure computational costs of different approaches, the value of time.clock is more useful than that of time.time(). |
4 | time.ctime([secs]) Like asctime(localtime(secs)) and without arguments is like asctime( ) |
5 | time.gmtime([secs]) Accepts an instant expressed in seconds since the epoch and returns a time-tuple t with the UTC time. Note : t.tm_isdst is always 0 |
6 | time.localtime([secs]) Accepts an instant expressed in seconds since the epoch and returns a time-tuple t with the local time (t.tm_isdst is 0 or 1, depending on whether DST applies to instant secs by local rules). |
7 | time.mktime(tupletime) Accepts an instant expressed as a time-tuple in local time and returns a floating-point value with the instant expressed in seconds since the epoch. |
8 | time.sleep(secs) Suspends the calling thread for secs seconds. |
9 | time.strftime(fmt[,tupletime]) Accepts an instant expressed as a time-tuple in local time and returns a string representing the instant as specified by string fmt. |
10 | time.strptime(str,fmt='%a %b %d %H:%M:%S %Y') Parses str according to format string fmt and returns the instant in time-tuple format. |
11 | time.time( ) Returns the current time instant, a floating-point number of seconds since the epoch. |
12 | time.tzset() Resets the time conversion rules used by the library routines. The environment variable TZ specifies how this is done. |
Let us go through the functions briefly −
There are following two important attributes available with time module −
Sr.No | Attribute with Description |
---|---|
1 | time.timezone Attribute time.timezone is the offset in seconds of the local time zone (without DST) from UTC (>0 in the Americas; <=0 in most of Europe, Asia, Africa). |
2 | time.tzname Attribute time.tzname is a pair of locale-dependent strings, which are the names of the local time zone without and with DST, respectively. |
- Related Articles
- The calendar Module in Python
- The Threading Module in Python
- Fraction module in Python
- colorsys module in Python
- Keyboard module in Python
- Import module in Python
- struct module in Python
- Pygorithm module in Python
- Python getpass Module
- Explain calendar module in python?
- Import a module in Python
- OS Path module in Python
- How to use the Subprocess Module in Python?
- Documentation generation using the pydoc module in Python
- Accessing the internet using the urllib.request module in Python

Advertisements