小編給大家分享一下calendar怎樣篩選出python3時(shí)間中重復(fù)事件,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

例如,Python 亞特蘭大用戶組在每個(gè)月的第二個(gè)星期四開會(huì)。要計(jì)算一年的會(huì)議日期,請(qǐng)使用monthcalendar()。
import calendar import pprint pprint.pprint(calendar.monthcalendar(2017, 7)) # 輸出 # [[0, 0, 0, 0, 0, 1, 2], # [3, 4, 5, 6, 7, 8, 9], # [10, 11, 12, 13, 14, 15, 16], # [17, 18, 19, 20, 21, 22, 23], # [24, 25, 26, 27, 28, 29, 30], # [31, 0, 0, 0, 0, 0, 0]]
0 值是與給定月份重疊的一周中的時(shí)間,是另一個(gè)月的一部分。
一周的第一天默認(rèn)為星期一。可以通過調(diào)用setfirstweekday()來更改,但由于日歷模塊包含用于索引返回的日期范圍的常量 monthcalendar(),因此在這種情況下跳過該步驟更方便。
要計(jì)算一年的小組會(huì)議日期,假設(shè)它們總是在每個(gè)月的第二個(gè)星期四,查看 monthcalendar()輸出來查找星期四。本月的第一周和最后一周填充 0 值作為前一個(gè)月或后一個(gè)月天數(shù)的占位符。例如,如果一個(gè)月在星期五開始,則星期四位置第一周的值將為 0。
import calendar
import sys
year = int(sys.argv[1])
# Show every month
for month in range(1, 13):
# Compute the dates for each week that overlaps the month
c = calendar.monthcalendar(year, month)
first_week = c[0]
second_week = c[1]
third_week = c[2]
# If there is a Thursday in the first week,
# the second Thursday is # in the second week.
# Otherwise, the second Thursday must be in
# the third week.
if first_week[calendar.THURSDAY]:
meeting_date = second_week[calendar.THURSDAY]
else:
meeting_date = third_week[calendar.THURSDAY]
print('{:>3}: {:>2}'.format(calendar.month_abbr[month], meeting_date))
# 輸出
# Jan: 12
# Feb: 9
# Mar: 9
# Apr: 13
# May: 11
# Jun: 8
# Jul: 13
# Aug: 10
# Sep: 14
# Oct: 12
# Nov: 9
# Dec: 14看完了這篇文章,相信你對(duì)calendar怎樣篩選出python3時(shí)間中重復(fù)事件有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
文章標(biāo)題:calendar怎樣篩選出python3時(shí)間中重復(fù)事件-創(chuàng)新互聯(lián)
當(dāng)前鏈接:http://chinadenli.net/article6/cojoig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、品牌網(wǎng)站制作、ChatGPT、自適應(yīng)網(wǎng)站、網(wǎng)站內(nèi)鏈、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容