Getting current time in Python


To translate a time instant from a seconds since the epoch floating-point value into a time-tuple, pass the floating-point value to a function (e.g., localtime) that returns a time-tuple with all nine items valid.

Example

 Live Demo

#!/usr/bin/python
import time;
localtime = time.localtime(time.time())
print "Local current time :", localtime

Output

This would produce the following result, which could be formatted in any other presentable form −

Local current time : time.struct_time(tm_year=2013, tm_mon=7,
tm_mday=17, tm_hour=21, tm_min=26, tm_sec=3, tm_wday=2, tm_yday=198, tm_isdst=0)

Updated on: 28-Jan-2020

109 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements