Flat 10% & upto 50% off + 10% Cashback + Free additional Courses. Hurry up
  • Live Instructor-led Classes
  • Expert Education
  • 24*7 Support
  • Flexible Schedule


It is used to retrieve current date and time. localtime() function is used to retrieve the current time and take time.time() parameter where time() is a function which returns the current system time in number of ticks since epoch (12 January 1970). Tick is basically a floating point number in seconds since epoch.

import time;
localtime = time.localtime(time.time())
print  localtime


time.struct_time(tm_year=2015, tm_mon=10, tm_mday=29, tm_hour=13,

tm_min=48, tm_sec=29, tm_wday=3, tm_yday=302, tm_isdst=0)


The time returned is a time structure which includes 9 attributes which are:

Attribute Description
tm_year Returns the current year
tm_mon Returns the current month
tm_mday Returns the current month day
tm_hour Returns the current hour.
tm_min Returns the current minute
tm_sec Returns current seconds
tm_wday Returns the week day
tm_yday Returns the year day.
tm_isdst It returns -1, 0 or 1.


Formatted Time

To retrieve the time in format use asctime().

import time;localtime = time.asctime( time.localtime(time.time()) )

print localtime


Thu Oct 29 13:56:05 2015


Time module:

Time module provides the number of functions which are used to work with time and for convert between representations.

Methods Description
sleep(time) By this execution will be stopped for the given interval of time.
strptime(string, format) Returns tuple with nine time attributes and obtain an String of date and a format.
time.clock() Return the current CPU time as floating point numbers of seconds
time.mktime() Returns second in floating point since epoch. etc



Python also provide the facility to display the calendar like as follows:

import calendar

calc = calendar.month(2015,10)

print calc


October 2015

Mo  Tu  We  Th  Fr  Sa  Su

                       1     2    3   4

 5     6    7     8    9  10   11

12   13  14  15  16  17  18

19   20 21  22 23  24   25

26  27 28 29  30 31


Calendar Module

Calendar module provides number of functions which is work on calendar. Some functions are –

Methods      Description
prcal(year) Returns the whole calendar of the specified year.
firstweekday() Returns the first week day
monthcalendar(year,month) Returns the calendar of specified month in that year
isleap(year) Check whether year is leap or not if yes than return true otherwise false
leapdays(yr1,yr2) Return number of leap days from year1 to year2
Previous Next

Download Interview Questions asked by top MNCs in 2018?

Learn SQL in 16 hrs from experts

"0 Responses on Python Date and Time"

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

Sales Offer

Sign Up or Login to view the Free Python Date and Time.