如何使用 Python 獲取一週的第一天?


可以使用日曆模組來用 Python 獲取一週的第一天。日曆模組有一個特殊函式 firstweekday(),它返回每週開始的當前設定。

示例

import calendar
print(calendar.firstweekday())
calendar.setfirstweekday(2)
print(calendar.firstweekday())

輸出

這會給出以下輸出 −

6
2

更新時間: 12-Jun-2020

2K+ 次瀏覽

開啟您的 事業

透過完成本課程獲得認證

開始
廣告
© . All rights reserved.