Python:一个月的第三个星期五

Python:一个月的第三个星期五,第1张

Python:一个月的第三个星期

应该这样做:

from datetime import datetimedef is_third_friday(s):    d = datetime.strptime(s, '%b %d, %Y')    return d.weekday() == 4 and 15 <= d.day <= 21

测试

print is_third_friday('Jan 18, 2013')  # Trueprint is_third_friday('Feb 22, 2013')  # Falseprint is_third_friday('Jun 21, 2013')  # Trueprint is_third_friday('Sep 20, 2013')  # True


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5675022.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存