This article describes how to return the day of the week by date in python, and describes how to use the date module in Python, for more information about how python returns the day of the week Based on the date, see the example in this article. 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:
The Code is as follows:
Print (get_week_day (datetime. datetime. now ()))
Output result:
Monday
I hope this article will help you with Python programming.