python从输入日期获取工作日 [英] python getting weekday from an input date
问题描述
我正在尝试处理一个家庭作业问题,其中输入日期的格式为YYYY-MM-DD
I'm trying to work on a homework problem where I have an input date in the format YYYY-MM-DD
我需要导入几个模块,然后创建一个函数工作日,它将日期分开并返回工作日。
I need to import a couple modules and create a function weekday where it splits up the date and returns the weekday.
到目前为止,我已导入:
So far I imported:
from time import *
from datetime import *
我在工作日函数中需要帮助,必须使用 .split
方法
I need help in my weekday function where I must use a .split
method
创建 datetime.date
类的对象。
并使用 strftime
返回全文中的星期几。
Create an object of the class datetime.date
.
and use strftime
to return the day of the week in full text.
谁能帮助我开始正确地实现这些功能和模块?
Can anyone help me get started on how to implement these functions and modules properly?
推荐答案
假设 s
是您的输入字符串:
Suppose s
is your input string:
s = '2010-10-29'
在提示时,尝试 s .split('-')
。会发生什么事?
At the prompt, try s.split('-')
. What happens?
创建一个日期
对象:
d = datetime.date(2010, 10, 29)
然后运行 d.strftime('%B')
。怎么了?
您可以填写其余部分。查看Python文档以获取更多信息。 Python文档:时间, datetime
You can fill in the rest. Look at the Python docs for more information. Python doc: time, datetime
这篇关于python从输入日期获取工作日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!