Python time time() method

Python Time time() Method

Description

The time() method returns the number of seconds since the epoch as a floating-point number, expressed in the UTC time zone.

Note – Although the time is always returned as a floating-point number, not all systems can provide a precision better than 1 second. Although this function normally returns a non-decreasing value, it can return a lower value than the previous call if the system clock has been set back between calls.

Syntax

The following is the syntax of the time() method:

time.time()

Parameters

NA

Return Value

This method returns the time in seconds since the epoch as a floating-point number, expressed in UTC.

Example

The following example shows the use of the time() method.

import time
print ("time.time(): %f " % time.time())
print (time.localtime( time.time() ))
print (time.asctime( time.localtime(time.time()) ))

When we run the above program, it produces the following output –

time.time(): 1681930077.653530
time.struct_time(tm_year=2023, tm_mon=4, tm_mday=20, tm_hour=0, tm_min=17, tm_sec=57, tm_wday=3, tm_yday=110, tm_isdst=0)
Thu Apr 20 00:17:57 2023

Leave a Reply

Your email address will not be published. Required fields are marked *