YouTip LogoYouTip

Python Exercise Example16

# Python2.x Python Exercise Instance 16 [![Image 3: Python 100 Examples](#) Python 100 Examples](#) **Question:** Output the date in a specified format. **Program Analysis:** Use the datetime module. ## Instance ```python #!/usr/bin/python # -*- coding: UTF-8 -*- import datetime if __name__ == ' __main__ ': # Output today's date in the format dd/mm/yyyy. For more options, see strftime() Method print(datetime.date.today().strftime('%d/%m/%Y')) # Create Date Object miyazakiBirthDate = datetime.date(1941, 1, 5) print(miyazakiBirthDate.strftime('%d/%m/%Y')) # Date Arithmetic miyazakiBirthNextDay = miyazakiBirthDate + datetime.timedelta(days=1) print(miyazakiBirthNextDay.strftime('%d/%m/%Y')) # Date Replacement miyazakiFirstBirthday = miy
← Python Exercise Example17Python Exercise Example15 β†’