年份的第几周"/>
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判断某个日期在所属年份的第几周
发布评论