Python 3+
1.) Implement a class Date that supports themethods:
a) __int__(): Constructor that takes no arguments andinitializes the date in the Date object to the current date.
b) display(): Takes a format argument and displays the date inthe requested format.
Use function localtime() from the Standard Library module timeto obtain the current date. The format argument is a string.
- ‘MDY’ : MM/DD/YY (04/09/19)
- ‘MDYY ‘ : MM/DD/YYYY (04/09/2019
- ‘DMY’ : DD/MM/YY (09/04/19)
- ‘DMYY’ : DD/MM/YYYY (09/04/2019)
- ‘MODY’ : Mon DD, YYYY (April 9, 2019)
Use methods localtime() and strftime() from the Standard Librarymodule time.
>>> x = Date()
>>> x.display(‘MDY’)
’04/09/19′
>>> x.display(‘MDYY’)
’04/09/2019′
>>> x.display(‘MODY’)
‘Apr 09, 2019’
>>> x.display(‘DMYY’)
’09/04/2019′
>>>
Solution