python代码通过日期获得星期信息(根据日期获取星期day of the week)

Posted Data+Science+Insight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python代码通过日期获得星期信息(根据日期获取星期day of the week)相关的知识,希望对你有一定的参考价值。

python代码通过日期获得星期信息(根据日期获取星期day of the week)

 

See the source image

 

# 通过具体日期获得日期所在的星期信息

# Python program to Find day of 
# the week for a given date 
import re #regular expressions
import calendar  #module of python to provide useful fucntions related to calendar
import datetime # module of python to get the date and time 

def process_date(user_input):
    user_input=re.sub(r"/", " ", user_input) #substitute / with space
    user_input=re.sub(r"-", " ", user_input) #substitute - with space 
    return user_input

def find_day(date):
    born = datetime.datetime.strptime(date, \'%d %m %Y\').weekday() 
    #this statement returns an integer corresponding to the day of the week
    return (calendar.day_name[born]) 
#this statement returns the corresponding day name to the inte

以上是关于python代码通过日期获得星期信息(根据日期获取星期day of the week)的主要内容,如果未能解决你的问题,请参考以下文章