Přeskočit na hlavní obsah

Příspěvky

Zobrazují se příspěvky se štítkem datetime

Python program | Najděte včerejší, dnešní a zítřejší datum

  # Python program to find yesterday, # today and tomorrow # Import datetime and timedelta # class from datetime module from datetime import datetime , timedelta # Get today's date presentday = datetime.now() # or presentday = datetime.today() # Get Yesterday yesterday = presentday - timedelta( 1 ) # Get Tomorrow tomorrow = presentday + timedelta( 1 ) # strftime() is to format date according to # the need by converting them to string print ( "Yesterday = " , yesterday.strftime( '%d-%m-%Y' )) print ( "Today = " , presentday.strftime( '%d-%m-%Y' )) print ( "Tomorrow = " , tomorrow.strftime( '%d-%m-%Y' )) Prerequisites: datetime module We can handle Data objects by importing the module datetime and timedelta to work with dates. datetime module helps to find the present day by using the now() or today() method. timedelta class from datetime module helps to find the previous day date and next day date. Moje fotografie , hudbu ne...