datetime
Refer to
https://docs.python.org/3/library/datetime.html
Use the datetime module to write a program that gets the current date and prints the day of
the week.
from datetime import datetime as dt
ct = dt.now()
print("Week day", ct.weekday())
Write a program that takes a birthday as input and prints the user’s age and the number of
days, hours, minutes and seconds until their next birthday.
use the timedelta object that is created with the difference.
from datetime import date
ct = dt.now()
print("Birthday is on 9th May 2020")
bday_this_year=dt(ct.year,5,9)
if bday_this_year > ct:
tb=bday_this_year - ct
print(tb, "to birthday"))
https://docs.python.org/3/library/datetime.html
Use the datetime module to write a program that gets the current date and prints the day of
the week.
datetime.nowdatetime.weekday() :Return the day of the week as an integer, where Monday is 0 and Sunday is 6. The same as self.date().weekday().
Comments
Post a Comment