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.mzph.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{"先主","将军","却说","荆州","二人","不可","不能","如此","忽然","下马","喊声","马…