Python returns the day of the week Based on the date. python returns the day of the week
This example describes how to return the day of the week by date in python. Share it with you for your reference. The details are as follows:
Given a date, this function outputs the day of the week. As for whether 0 is Monday or Sunday, this is related to the time zone. Anyway, if 0 is used here, it indicates Monday.
Import time, datetimedef get_week_day (date): week_day_dict = {0: 'monday', 1: 'tuesday', 2: 'wedday', 3: 'thurs', 4: 'Friday', 5: 'saturday', 6: 'sunday',} day = date. weekday () return week_day_dict [day]
If you want to output the day of the week, run the following code:
Copy codeThe Code is as follows: print (get_week_day (datetime. datetime. now ()))
Output result:
Monday
I hope this article will help you with Python programming.