Python data and time
You can use the most interesting module in python that is dates. The module called DateTime is generally used to deals with date objects. We can easily display the date structure of the system in python using some inbuilt functions.
Example1:
#this program will print the current date structure of system
import datetime
kk = datetime.datetime.now()
print(kk)
Example2:
import time;timet = time.localtime(time.time())print ("Local current time :", timet)
Date time constructor:
From the datetime module, you can import datetime() which is the constructor, and create date.
This function generally needs a three-parameter passed to it in the form of year, month, day.
Example:
#using constructor
import datetime
abb = datetime.datetime(2020, 5, 17)
print(abb)
strftime method in python:
strftime() method is imported from the datetime module and used for formatting using a Variety of codes.
Example:
#1import datetimexyy = datetime.datetime(2018, 6, 1)print(xyy.strftime("%B"))#2import datetimexyy = datetime.datetime(2018, 6, 1)print(xyy.strftime("%B"))
Calendar of the specified month:
Here we can play while learning, using methods in python. month() method will take two arguments that are years and month.
Example:
#calendar program using calender moduleimport calendarcal1 = calendar.month(2020, 6)print ("Here is the calendar:")print (cal)
