The code below shows how to get the current time using the
datetime module. The now() method returns a datetime object representing the current date and time according to the system clock. The strftime() method formats the time for the desired output. This code shows how to use the datetime module together with the strftime() method to get a formatted time string in the format of hours, minutes, and seconds.from datetime import datetime
time_now = datetime.now().strftime('%H:%M:%S')
print(f'Current time: {time_now}')
Current time: 17:37:28
What if we want to return today's date? We can use
date from the datetime module. Below, the today() method is used:from datetime import date
today_date = date.today()
print(today_date)
2023-09-20
👉 https://t.me/DataScience4