Python Date

Python Date Related Modules:

Python datetime module and Python time module both contains various built in functions and statements to deal with all type of date and time operations in the python code. Python facilitates numerous Date and Time features to its users that eases any required date and time interfacing in the program.

Python Datetime Module:

The datetime module returns information about the date object in various format. In normal scenario, the date retrieved contains current year, month, day, hour, minute, second, and even microsecond.

Python Time Module:

The ime module returns information about the time object in various format. In normal scenario, the time retrieved includes 9 attributes.

ATTRIBUTE EXPLANATION
tm_year Current year
tm_mon Current month
 tm_mday Current month day
tm_hour Current hour
tm_min Current minute
tm_sec Current seconds
tm_wday Week day
 tm_yday Year day
tm_isdst -1,0 or 1

 

Python Time Module Methods:

FUNCTION USES
time() To get floating point value in seconds since epoch.
asctime() To get a 24 character string, taking the tuple returned by localtime() as parameter.
sleep() To stop the code execution for the given interval of time.
strptime() To get a tuple with all 9 time attributes.
gtime() To get struct_time which contains 9 time attributes.
mktime() To get seconds in floating point since epoch.
strftime() To get time in a specified format.

 

Python Calendar Module:

Python Calendar module contains various built in functions and statements to deal with all type of calendar related operations in the python code.

FUNCTION USES
prcal() To print whole calendar of the year.
firstweekday() To get the first week day.
isleap() To get a True value in case given year is leap else false.
monthcalendar() To get the given month with each week in a single list.
leapdays() To get the number of leap days between two years.
prmonth() To print the given month of the given year.

 

Example:

import calendar
year = input("Enter year to view: ")
month = input("Enter month to view: ")
print(calendar.month(year,month))

Output:

Please follow and like us:
Content Protection by DMCA.com