[轉載] Python日曆模組| 使用示例的weekday()方法
參考連結: Python中的日曆函式 2(monthrange(),prcal(),weekday()…)
Python calendar.weekday()方法 (Python calendar.weekday() Method)
weekday() method is an inbuilt method of the calendar module in Python. It works on simple text calendars and returns what is the day of the week for the given year, month and day mentioned in the function argument. Here Monday denotes 0 and incrementing the following days by one for the year(1970–…), month (1–12), day (1–31).
weekday()方法是Python中日曆模組的內建方法。 它適用於簡單的文字日曆,並返回函式引數中給定的年,月和日的星期幾。 在這裡,星期一表示0,然後將年(1970–…),月(1–12),天(1–31)的第二天增加1。
Module:
模組:
import calendar
Syntax:
句法:
weekday(year, month, day)
Parameter(s):
引數:
year: It is a required parameter, which represents the year value of the calendar year :這是必填引數,代表日曆的年份 month: It is a required parameter, which represents the month value of the calendar month :這是必填引數,代表日曆的月份值 day: It is a required parameter, which represents the day of the month. day :這是必填引數,代表月份中的一天。
Return value:
返回值:
The return type of this method is <class 'int'>, it returns a number which is the day on this given year, month and day. Monday is 0 and Sunday is 6.
此方法的返回型別為<class'int'> ,它返回一個數字,該數字是該給定的年,月和日的日期。 星期一是0,星期日是6。
Example:
例:
# Python program to illustrate the
# use of weekday() method
# importing calendar module
import calendar
year = 2020
month = 2
day = 20
x = calendar.weekday(year, month, day)
print("Weekday number for the given date:", x)
print()
# We can also make a list of days and
# print the day name accordingly
wday = ['Monday', "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
year = 1996
month = 10
day = 27
x = calendar.weekday(year, month, day)
print("Weekday number:", x)
print("Weekday name:", wday[x])
Output
輸出量
Weekday number for the given date: 3
Weekday number: 6
Weekday name: Sunday
Note: The date in the function argument should be valid, otherwise it will raise a ValueError.
注意:函式引數中的日期應有效,否則將引發ValueError 。
For example, if you print 31 September 2019, this will be wrong as September has only 30 days.
例如,如果您列印2019年9月31日 ,這將是錯誤的,因為9月只有30天。
Example:
例:
# Python program to illustrate the
# use of weekday() method
# importing calendar module
import calendar
year = 2019
month = 2
day = 29
x = calendar.weekday(year, month, day)
print("Weekday number for the given date:", x)
print()
Output
輸出量
Traceback (most recent call last):
File "main.py", line 11, in <module>
x = calendar.weekday(year, month, day)
File "/usr/lib/python3.8/calendar.py", line 117, in w
eekday
return datetime.date(year, month, day).weekday()
ValueError: day is out of range for month
翻譯自: https://www.includehelp.com/python/calendar-weekday-method-with-example.aspx
相關文章
- Python模組以及日曆常見用法Python
- Python3 日曆(Calendar)模組介紹Python
- Python模組 adorner 的使用示例Python
- Python重新載入模組方法Python
- Python模組過載的五種方法Python
- Python的socket模組及示例Python
- 使用python 下載全國曆代古詩Python
- 如何在Mac中使用佛教日曆,波斯日曆等Mac
- Oracle和JDE日曆轉換Oracle
- 日曆函式單元 (轉)函式
- win10電腦日曆怎麼顯示農曆_win10系統日曆顯示農曆的設定方法Win10
- 在access中增加農曆支援模組. (轉)
- Java 周曆日曆Java
- python-包及日誌模組使用Python
- Win10系統日曆新事件不能使用的解決方法Win10事件
- JS編寫日曆控制元件(支援單日曆 雙日曆 甚至多日曆等)JS控制元件
- 20個Python random模組的程式碼示例Pythonrandom
- Calendar日曆型別常見方法(必看!!)型別
- Python筆記之paramiko模組安裝和使用示例Python筆記
- 陽曆到陰曆的轉換 (轉)
- 相當於delphi的日曆控制元件 (轉)控制元件
- 在 Linux 命令列上使用日曆Linux命令列
- win10 更改日曆方法 win10 日曆怎麼更改Win10
- 【SQL】日曆SQL
- Win10系統日曆應用顯示農曆日期的方法【圖文】Win10
- win10在日曆裡顯示天氣和農曆的方法_win10怎麼讓日曆磁貼顯示農曆和天氣Win10
- 使用RecycleView實現無限滾動的日曆View
- python下載模組Python
- win10日曆顯示日程安排的方法_win10如何讓日曆顯示日程安排Win10
- win10系統日曆備忘錄在哪裡_win10開啟日曆備忘錄的方法Win10
- 日曆2021年日曆表|2021年日曆表列印版 Excel版Excel
- JavaScript 實現日曆式日期選擇 (轉)JavaScript
- python re模組常見使用方法整理Python
- python 安裝模組的方法Python
- [轉載] python數學計算模組之math常用函式學習使用Python函式
- 日曆外掛
- 日曆計算
- Python:使用logging模組記錄日誌Python