python判断某个日期在所属年份的第几周

编程入门 行业动态 更新时间:2024-10-07 10:25:16

python判断某个日期在所属<a href=https://www.elefans.com/category/jswz/34/1766180.html style=年份的第几周"/>

python判断某个日期在所属年份的第几周

import datetimedef convert_date(date_string):format_form = ['%Y-%m-%d', '%Y-%m-%d %H:%M:%S', '%Y/%m/%d', '%Y/%m/%d %H:%M:%S']for form in format_form:try:formated_date = datetime.datetime.strptime(date_string, form)breakexcept Exception:continueelse:print(f'当前外观总检时间({date_string})格式不支持读取,请更换日期格式!')return ''year = formated_date.yearif int(datetime.datetime(year, 1, 1).strftime('%W')) != 1:current_week = int(formated_date.strftime('%W')) + 1else:current_week = int(formated_date.strftime('%W'))if current_week < 10:format_week = f'W0{current_week}'else:format_week = f'W{current_week}'return format_weekconvert_date('2023-01-01') # W01

更多推荐

python判断某个日期在所属年份的第几周

本文发布于:2023-11-30 12:35:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650167.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:年份   几周   日期   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!