当前位置: 首页 > wzjs >正文

跨境网站有哪些中国建设银行官方网站 认证

跨境网站有哪些,中国建设银行官方网站 认证,html5网页制作代码大全,网站备案怎么这么麻烦目录 专栏导读1、背景介绍2、库的安装代码1:当月第一天、昨天代码2:上月第一天、当天代码3:上月第一天、明天代码4:检查某天是否是法定节假日代码5:获取2025年所有法定节假日总结 专栏导读 🌸 欢迎来到Pyth…

目录

  • 专栏导读
  • 1、背景介绍
  • 2、库的安装
  • 代码1:当月第一天、昨天
  • 代码2:上月第一天、当天
  • 代码3:上月第一天、明天
  • 代码4:检查某天是否是法定节假日
  • 代码5:获取2025年所有法定节假日
  • 总结

专栏导读

  • 🌸 欢迎来到Python办公自动化专栏—Python处理办公问题,解放您的双手

  • 🏳️‍🌈 博客主页:请点击——> 一晌小贪欢的博客主页求关注

  • 👍 该系列文章专栏:请点击——>Python办公自动化专栏求订阅

  • 🕷 此外还有爬虫专栏:请点击——>Python爬虫基础专栏求订阅

  • 📕 此外还有python基础专栏:请点击——>Python基础学习专栏求订阅

  • 文章作者技术和水平有限,如果文中出现错误,希望大家能指正🙏

  • ❤️ 欢迎各位佬关注! ❤️

1、背景介绍

  • 我们在日常办公中,经常会需要获取当前月份的第一天、昨天;

  • 我们在日常办公中,经常会需要获取上个月份的第一天、当天;

2、库的安装

用途安装
datetime处理日期内置库无需安装
datetime处理日期pip install chinesecalendar

代码1:当月第一天、昨天

# -*- coding: UTF-8 -*-
'''
@Project :8组-邹佩佩-差异线上化 
@File    :测试.py
@IDE     :PyCharm 
@Author  :庄志权(18721945973)
@Date    :2025/3/27 15:05 
'''import datetimedef get_first_last_day_of_month():# 获取当前日期now = datetime.datetime.now()# 获取当前月份的第一天first_day_of_month = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)# 获取当天的前一天(昨天)last_day = now - datetime.timedelta(days=1)last_day = last_day.replace(hour=23, minute=59, second=59, microsecond=0)# 输出结果# print(f'当前日期: {now.strftime("%Y-%m-%d")}')print(f'本月第一天: {first_day_of_month.strftime("%Y-%m-%d")}')print(f'前一天: {last_day.strftime("%Y-%m-%d")}')first_day_of_month = first_day_of_month.strftime("%Y-%m-%d")last_day = last_day.strftime("%Y-%m-%d")return first_day_of_month, last_dayget_first_last_day_of_month()

代码2:上月第一天、当天

from datetime import datetime, date, timedeltadef get_last_month_dates():# 获取当前日期today = date.today()# 计算上个月的第一天if today.month == 1:last_month_first_day = date(today.year - 1, 12, 1)else:last_month_first_day = date(today.year, today.month - 1, 1)# 格式化日期为YYYY-MM-DDlast_month_first_day_str = last_month_first_day.strftime("%Y-%m-%d")today_str = today.strftime("%Y-%m-%d")return last_month_first_day_str, today_str# 示例用法
last_month_first, current_day = get_last_month_dates()
print(f"上月第一天: {last_month_first}, 当天: {current_day}")

代码3:上月第一天、明天

import calendar
from datetime import date, timedeltadef get_last_month_and_tomorrow():today = date.today()tomorrow = today + timedelta(days=1)# 计算上个月的第一天year = today.year - (1 if today.month == 1 else 0)month = 12 if today.month == 1 else today.month - 1last_month_first_day = date(year, month, 1)return last_month_first_day.strftime("%Y-%m-%d"), tomorrow.strftime("%Y-%m-%d")# 示例调用
print(get_last_month_and_tomorrow())

代码4:检查某天是否是法定节假日

pip install chinesecalendar
import chinesecalendar as calendar
from datetime import date# 检查日期是否节假日(包含调休的工作日)
day = date(2025, 10, 1)  # 2025年国庆节
is_holiday = calendar.is_holiday(day)
print(f"{day} 是节假日吗? {is_holiday}")  # 输出: True# 检查某天是否工作日(考虑调休)
is_workday = calendar.is_workday(day)
print(f"{day} 是工作日吗? {is_workday}")  # 输出: False

代码5:获取2025年所有法定节假日

pip install chinesecalendar
from datetime import date, timedeltadef get_holidays(year):holidays = []current = date(year, 1, 1)end = date(year, 12, 31)while current <= end:if calendar.is_holiday(current):# 获取节假日名称(通过遍历匹配)for name, dates in calendar.get_holiday_detail(current):holidays.append((current, name))break  # 只需第一个匹配名称current += timedelta(days=1)return holidays# 示例:打印2025年所有节假日
holidays_2025 = get_holidays(2025)
for day, name in holidays_2025:print(f"{day.strftime('%Y-%m-%d')}: {name}")

总结

  • 希望对初学者有帮助

  • 致力于办公自动化的小小程序员一枚

  • 希望能得到大家的【一个免费关注】!感谢

  • 求个 🤞 关注 🤞

  • 此外还有办公自动化专栏,欢迎大家订阅:Python办公自动化专栏

  • 求个 ❤️ 喜欢 ❤️

  • 此外还有爬虫专栏,欢迎大家订阅:Python爬虫基础专栏

  • 求个 👍 收藏 👍

  • 此外还有Python基础专栏,欢迎大家订阅:Python基础学习专栏


文章转载自:

http://6G7kXyAc.nfbnL.cn
http://OiqN7r0E.nfbnL.cn
http://fIZlMvtx.nfbnL.cn
http://oyZuiyZP.nfbnL.cn
http://AKtB8rXd.nfbnL.cn
http://zsv55UQq.nfbnL.cn
http://d7l4mJn7.nfbnL.cn
http://34hwzxEp.nfbnL.cn
http://lcSwnEip.nfbnL.cn
http://oTbwzgup.nfbnL.cn
http://JdDTVsYy.nfbnL.cn
http://IOJCm9nE.nfbnL.cn
http://NI05hkt6.nfbnL.cn
http://psbmpitJ.nfbnL.cn
http://EbxKOUuh.nfbnL.cn
http://RGBWhMkp.nfbnL.cn
http://2D2X5MjU.nfbnL.cn
http://toaroXz1.nfbnL.cn
http://F2Hey1CE.nfbnL.cn
http://F5yUkZjf.nfbnL.cn
http://VnVhmFV1.nfbnL.cn
http://3GcUXO2p.nfbnL.cn
http://mnRcwrD9.nfbnL.cn
http://Oy4UiuYH.nfbnL.cn
http://rnVV4U5M.nfbnL.cn
http://FOjgUU81.nfbnL.cn
http://ZVhmQKH3.nfbnL.cn
http://Ph3k7ACX.nfbnL.cn
http://SqAKGya5.nfbnL.cn
http://il14JjFZ.nfbnL.cn
http://www.dtcms.com/wzjs/631333.html

相关文章:

  • 广西建设监理协会官网站运营公众号需要多少钱
  • 建wap手机网站北滘网站建设公司
  • 房管局网站建设wordpress 预约主题
  • 网站建设合同属于印花税的哪个税目php网站开发打不开
  • 网站页面制作多少钱网站的域名和空间
  • 郑州建设网站哪家好计算机应用软件开发流程图
  • 政务网站建设管理的论文哪个行业最容易做网站
  • 手机版素材网站搜狗首页排名优化
  • 好看的旅游网站模板下载网页设计实训心得200字
  • 空间网站打不开百度网站建设费用怎么做账
  • 湘潭网站seo公司免费动画制作软件
  • 男女直接做免费的网站开发软件下载网站
  • 青岛建设项目环评公示网站专门做试卷的网站
  • 网站开发人才培养目标免费建工作室网站
  • 做植物提取物的专业网站诗词门户网站
  • 建筑公司网站广告宣传语于都做网站
  • 学生怎样做网站百度网盘做存储网站
  • 类似站酷的网站建站聊城做网站的公司精英
  • 东海建设局网站建设网站一般要多久
  • 北京网站建设公司服务哪家好做个平台网站怎么做的
  • 营口建设工程质量监督站网站网站建设 英语
  • 网站优化成本湄洲岛网站建设
  • 做网站都需要具备什么深圳网站系统找哪里
  • 重庆微信网站建设多少钱营销推广活动策划书模板
  • 上海住房和城乡建设部网站首页网站规划的缩略图
  • 淄博淘宝网站建设丹东市住房和城乡建设网站
  • 西南交通建设集团有限公司网站玉环市建设工程检测中心网站
  • 网站 可信验证c2c类型电子商务网站
  • 网站开发华企云商中国建设银行贷款官网站
  • 创建一个网站的费用网站打不开怎么回事