gpt4 book ai didi

python - 将日期字符串转换为星期几

转载 作者:IT老高 更新时间:2023-10-28 22:23:24 25 4
gpt4 key购买 nike

我有这样的日期字符串:

'January 11, 2010'

我需要一个返回星期几的函数,比如

'mon', or 'monday'

等等。我在 Python 帮助中的任何地方都找不到这个。任何人?谢谢。

最佳答案

您可能想使用 strptime and strftime来自 datetime 的方法:

>>> import datetime
>>> datetime.datetime.strptime('January 11, 2010', '%B %d, %Y').strftime('%A')
'Monday'

或者对于'Mon':

>>> datetime.datetime.strptime('January 11, 2010', '%B %d, %Y').strftime('%a')
'Mon'

关于python - 将日期字符串转换为星期几,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16766643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com