Python datetime isocalendar()方法與示例

Python datetime.isocalendar()方法 (Python datetime.isocalendar() Method)

datetime.isocalendar() method is used to manipulate objects of datetime class of module datetime.

datetime.isocalendar()方法用于操作模塊datetime的datetime類的對象。

It uses a datetime class object and returns a 3-tuple (ISO year, ISO week number, ISO weekday).

它使用datetime類對象并返回3元組(ISO年,ISO周號,ISO工作日)。

Most of the date and time calendar follow the Gregorian calendar. The ISO calendar is a widely used variant of the Gregorian one. The ISO year consists of 52 or 53 full weeks, and where a week starts on a Monday and ends on a Sunday. The first week of an ISO year is the first (Gregorian) calendar week of a year containing a Thursday. This is called week number 1, and the ISO year of that Thursday is the same as its Gregorian year.
For example, 2004 begins on a Thursday, so the first week of ISO year 2004 begins on Monday, 29 Dec 2003 and ends on Sunday, 4 Jan 2004:

大多數日期和時間日歷都遵循公歷。 ISO日歷是公歷之一的廣泛使用的變體。 ISO年度包括52或53個整周,其中一個星期從星期一開始,在星期日結束。 ISO年的第一周是包含星期四的一年中的第一個(格里高利歷)日歷周。 這稱為第1周,該周四的ISO年與其公歷年相同。
例如,2004年從星期四開始,因此ISO 2004年的第一周從2003年12月29日星期一開始,到2004年1月4日星期日結束:

Weekday number for Monday is 1 while incrementing by 1 for the coming days.

星期一的工作日數為1,而接下來的幾天則增加1。

Module:

模塊:

    import datetime

Class:

類:

    from datetime import datetime

Syntax:

句法:

    isocalendar()

Parameter(s):

參數:

  • None

    沒有

Return value:

返回值:

The return type of this method is a tuple which tells us what is the ISO year, ISO week and the ISO weekday of that date.

此方法的返回類型是一個元組,它告訴我們什么是ISO年,ISO周和該日期的ISO工作日。

Example:

例:

## importing datetime class
from datetime import datetime
## Creating an instance
x = datetime.now()
d = x.isocalendar()
print("Original date:",x)
print("Today's date in isocalendar is:", d)
print()
x = datetime(2004, 10, 30, 12, 12, 12)
d = x.isocalendar()
## this returns a date object, extracted from 
## the datetime object
dd = x.date()
print("Date", str(dd) ,"in isocalendar is:", d)
print()
x = datetime(2020, 10, 27, 10, 3, 33)
d = x.isocalendar()
dd = x.date()
print("Original date was:",str(dd))
print("ISO year:",d[0],"ISO week:",d[1],"ISO weekday:",d[2])

Output

輸出量

Original date: 2020-05-01 22:40:19.039474
Today's date in isocalendar is: (2020, 18, 5)
Date 2004-10-30 in isocalendar is: (2004, 44, 6)
Original date was: 2020-10-27
ISO year: 2020 ISO week: 44 ISO weekday: 2

翻譯自: https://www.includehelp.com/python/datetime-isocalendar-method-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379174.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379174.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379174.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ASP.NET 技術(附翻譯)

1.構建 ASP.NET 頁面ASP.NET 和ASP.NET結構ASP.NET 是微軟.NET framework整體的一部分, 它包含一組大量的編程用的類,滿足各種編程需要。 在下列的二個部分中, 你如何學會 ASP.NET 很適合的放在.NET framework, 和學會能在你的 ASP.NET 頁面中使用語言。.NET類庫假想…

SQL捕獲異常

原文地址 http://technet.microsoft.com/zh-cn/office/ms179296%28vsql.100%29在 Transact-SQL 中使用 TRY...CATCHTransact-SQL 代碼中的錯誤可使用 TRY…CATCH 構造處理,此功能類似于 Microsoft Visual C 和 Microsoft Visual C# 語言的異常處理功能。TRY…CATCH …

二叉樹遍歷(代碼,分析,匯編)

目錄:代碼:分析:匯編:代碼: BTree.h BTree.c 二叉樹(多路平衡搜索樹) LinkQueue.h #ifndef _LINKQUEUE_H_ #define _LINKQUEUE_H_typedef void LinkQueue;//定義隊列類型LinkQueue* LinkQueu…

Java Vector insertElementAt()方法與示例

矢量類insertElementAt()方法 (Vector Class insertElementAt() method) insertElementAt() method is available in java.util package. insertElementAt()方法在java.util包中可用。 insertElementAt() method is used to set the given element (ele) at the given (indices…

Python---查找序列的最長遞增子序列

查找序列的最長遞增子序列 什么是序列的最長遞增子序列? 答:在一個數值序列中,找到一個子序列,使得這個子序列元素的數值依次遞增,并且這個子序列的長度盡可能地大。這就是所謂的最長遞增子序列 from itertools impo…

SendMessage和PostMessage

SendMessage 和 PostMessage 的區別 1、首先是返回值意義的區別,我們先看一下 MSDN 里的聲明: LRESULT SendMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);BOOL PostMessage( HWND hWnd…

ffmpeg-從mp4、flv、ts文件中提取264視頻流數據

ffmpeg-從mp4、flv、ts文件中提取264視頻流數據 main.c #include <stdio.h> #include <libavutil/log.h> #include <libavformat/avio.h> #include <libavformat/avformat.h>void proc(int need_to_annexb, char* in_file, char* out_file) {AVForma…

java timezone_Java TimeZone getDSTSavings()方法與示例

java timezoneTimeZone類的getDSTSavings()方法 (TimeZone Class getDSTSavings() method) getDSTSavings() method is available in java.util package. getDSTSavings()方法在java.util包中可用。 getDSTSavings() method is used to get the number of time differences in …

Photoshop 保存PNG格式交錯和不交錯有差別

1.PNG格式是由Netscape公司開發出來的格式&#xff0c;可以用于網絡圖像&#xff0c;但它不同于GIF格式圖像只能保存256色&#xff0c;PNG格式可以保存24位的真彩色圖像&#xff0c;并且支持透明背景和消除鋸齒邊緣的功能&#xff0c;可以在不失真的情況下壓縮保存圖像。但由于…

線索化二叉樹(代碼 、分析 、匯編)

目錄&#xff1a;代碼&#xff1a;分析&#xff1a;匯編&#xff1a;代碼&#xff1a; BTree.h BTree.c 二叉樹&#xff08;多路平衡搜索樹&#xff09; SeqList.h SeqList.c 順序表 main.c #include <stdio.h> #include <stdlib.h> #include "BTree.h&qu…

Python---尋找給定序列中相差最小的兩個數字

編寫函數&#xff0c;尋找給定序列中相差最小的兩個數字 def getTwoClosestElements(arr):#先進行排序&#xff0c;使得相鄰元素最接近#相差最小的元素必然相鄰seq sorted(arr)#先進行排序dif float(inf)#無窮大#遍歷所有元素&#xff0c;兩兩比較&#xff0c;比較相鄰元素的…

ubuntu 無線 共享 上網

配置DHCP服務器 使連接到此AP的電腦 自動獲取IP 1. 安裝軟件包&#xff1a;sudo apt-get install dhcp3-server2. 修改/etc/default/dhcp3-server配置文件INTERFACES"eth1" //eth1為無線網卡的名字3. 修改/etc/dhcp3/dhcpd.conf配置文件option domain-name-servers …

Java StringBuilder getChars()方法與示例

StringBuilder類的getChars()方法 (StringBuilder Class getChars() method) getChars() method is available in java.lang package. getChars()方法在java.lang包中可用。 getChars() method is used to copy all the characters from the given arguments (int src_st, int …

Python---利用蒙特.卡羅方法計算圓周率近似值

利用蒙特.卡羅方法計算圓周率近似值 什么是蒙特.卡羅方法&#xff1f; 答&#xff1a;蒙特卡羅方法是一種計算方法。原理是通過大量隨機樣本&#xff0c;去了解一個系統&#xff0c;進而得到所要計算的值。 正方形內部有一個相切的圓&#xff0c;它們的面積之比是π/4。 這里假…

不具有繼承關系的Delegate如何進行類型轉換?

- 引自:Artech 我們知道對于兩個不具有繼承關系的兩個類型&#xff0c;如果沒有為它們定義轉換器&#xff0c;兩這之間的類型轉換是不允許的&#xff0c;Delegate也是如此。但是有時候我們卻希望“兼容”的兩種Delegate類型能夠進行轉換&#xff0c;比較典型的就是表示事件的De…

Java屬性loadFromXML()方法與示例

屬性類loadFromXML()方法 (Properties Class loadFromXML() method) loadFromXML() method is available in java.util package. loadFromXML()方法在java.util包中可用。 loadFromXML() method is used to load all the properties denoted by the XML file on the given inpu…

FLV封裝格式的分析

FLV封裝格式的分析&#xff0c;各種詳細的參數比較多沒有詳細解釋&#xff0c;這是總體的格式分布。詳細的參數說明可以參照文檔。 以flv格式內封裝的音頻流是aac、視頻流是h264分析&#xff1a; flv文件tag部分截圖&#xff1a;可以看到音頻TAG、視頻TAG是交錯存儲的

《計算機基礎復習》===數據庫技術基礎

數據庫系統三級結構&#xff1a; 數據庫系統一般劃分為三個抽象級&#xff1a;用戶級、概念級、物理級。 1&#xff09;用戶級數據庫&#xff1a;對應于外模式。它是用戶看到和使用的數據庫&#xff0c;又稱用戶視圖&#xff1b;用戶級數據庫主要由外部記錄組成&#xff0c;不同…

bs架構 erp 進銷存_從依賴經驗到用柔性ERP,企業少走了多少彎路?

企業在面對緊急訂單時&#xff0c;傳統企業將面臨兩難問題&#xff1a;如不接受緊急訂單,可能會導致潛在的顧客丟失,損失市場占有率;接受緊急訂單,可能會給企業帶來很多管理上的問題,如材料采購、庫存管理等。而企業通過信息化手段提升生產計劃與控制的柔性&#xff0c;則可從容…

Python---統計《三國演義》中出現次數較高的人物

統計《三國演義》中出現次數較高的人物。 import jieba excludes{"先主","將軍","卻說","荊州","二人","不可","不能","如此","忽然","下馬","喊聲","馬…