日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python获取上周周一日期_python python日期算法 本周,上周,本月,上月,本季,上季,今年, 去年...

發布時間:2023/12/20 python 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python获取上周周一日期_python python日期算法 本周,上周,本月,上月,本季,上季,今年, 去年... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

import datetime

from datetime import timedelta

now = datetime.datetime.now()

#今天

today = now

#昨天

yesterday = now - timedelta(days=1)

#明天

tomorrow = now + timedelta(days=1)
#當前季度

now_quarter = now.month / 3 if now.month % 3 == 0 else now.month / 3 + 1

#本周第一天和最后一天

this_week_start = now - timedelta(days=now.weekday())

this_week_end = now + timedelta(days=6-now.weekday())

#上周第一天和最后一天

last_week_start = now - timedelta(days=now.weekday()+7)

last_week_end = now - timedelta(days=now.weekday()+1)

#本月第一天和最后一天

this_month_start = datetime.datetime(now.year, now.month, 1)

this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1)

#上月第一天和最后一天

last_month_end = this_month_start - timedelta(days=1)

last_month_start = datetime.datetime(last_month_end.year, last_month_end.month, 1)

#本季第一天和最后一天

month = (now.month - 1) - (now.month - 1) % 3 + 1

this_quarter_start = datetime.datetime(now.year, month, 1)

this_quarter_end = datetime.datetime(now.year, month + 3, 1) - timedelta(days=1)

#上季第一天和最后一天

last_quarter_end = this_quarter_start - timedelta(days=1)

last_quarter_start = datetime.datetime(last_quarter_end.year, last_quarter_end.month - 2, 1)

#本年第一天和最后一天

this_year_start = datetime.datetime(now.year, 1, 1)

this_year_end = datetime.datetime(now.year + 1, 1, 1) - timedelta(days=1)

#去年第一天和最后一天

last_year_end = this_year_start - timedelta(days=1)

last_year_start = datetime.datetime(last_year_end.year, 1, 1)

總結

以上是生活随笔為你收集整理的python获取上周周一日期_python python日期算法 本周,上周,本月,上月,本季,上季,今年, 去年...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。