from datetime import datetime
from chinese_calendar import is_workday, is_holiday, is_in_lieu, get_holiday_detail
# 定义两个时间字符串
time_str1 = "2024-10-12 18:41:02"
time_str2 = "2024-10-12 17:30:00"
# 将时间字符串转换为datetime对象
time1 = datetime.strptime(time_str1, "%Y-%m-%d %H:%M:%S")
time2 = datetime.strptime(time_str2, "%Y-%m-%d %H:%M:%S")
# 计算时间差
time_difference = time1 - time2
# 将时间差转换为小时和分钟
hours, minutes = divmod(time_difference.total_seconds(), 3600)
# 输出结果
print(f"两个字符串之间的时间间隔为 {int(hours)} 小时 {int(minutes)} 分钟")
print("小时:",time_difference.total_seconds()/3600)
print("分钟:",time_difference.total_seconds()/60)
def is_statistic_date(datetimet):
'''
判断当前日期是否为统计日期
'''
OnHoliday, HolidayName = get_holiday_detail(datetimet)
return is_workday(datetimet) or HolidayName == None
标签:-%,python,datetime,时间,time,字符串,非法定,difference
From: https://www.cnblogs.com/hanwang/p/18467782