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:

tm_yearReturns the current year
tm_monReturns the current month
tm_mdayReturns the current month day
tm_hourReturns the current hour.
tm_minReturns the current minute
tm_secReturns current seconds
tm_wdayReturns the week day
tm_ydayReturns the year day.
tm_isdstIt 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.

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

Leave a Reply

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

Solve : *
19 + 30 =