带有示例的Python datetime weekday()方法

news/2024/7/20 23:05:27 标签: python, java, django, , ios

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

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

datetime.weekday()方法用于操作模块datetime的datetime的对象。

It uses a datetime class object and returns the day of the week as an integer, where Monday is 0 and Sunday is 6. It is an instance method, i.e., it works on an instance of the class.

它使用datetime对象,并以整数形式返回星期几,其中Monday是0,Sunday是6。它是一个实例方法,即,它适用于该的实例。

Module:

模块:

    import datetime

Class:

    from datetime import datetime

Syntax:

句法:

    weekday()

Parameter(s):

参数:

  • None

    没有

Return value:

返回值:

The return type of this method is a number which tells us what is the day of the week on that day.

此方法的返回型是一个数字,该数字告诉我们当天的星期几。

Example:

例:

## importing datetime class
from datetime import datetime

## Creating an instance
x = datetime.today()
d = x.weekday()
print("Today's weekday number is:", d)

x = datetime(1996, 10,27, 21, 5, 5)
d1 = x.weekday()
xd = x.date()
print("Weekday number on the date", xd,"will be:",d1)
print()

## Since we know the number, 
## we can save them in a list and 
## print the day on that number
day =["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
print("Today's day is:",day[d])
print("Day on date", x," was:", day[d1])

Output

输出量

Today's weekday number is: 5
Weekday number on the date 1996-10-27 will be: 6

Today's day is: Saturday
Day on date 1996-10-27 21:05:05  was: Sunday


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


http://www.niftyadmin.cn/n/1255141.html

相关文章

软件项目立项报告_攀枝花市教育信息化2.0软件项目可行性研究报告顺利通过专家组评审...

10月15日,受市教育和体育局委托,市经济与信息化局组织专家组对攀枝花市教育信息化2.0软件项目可行性研究报告进行了专家评审,评审会议在市教育科学研究院会议室举行。市发展改革委、市经济和信息化局、市教育和体育局、市财政局、攀枝花浪潮公…

python测试代码与模块_python单元测试模块

在Python中编写单元测试可以使用标准库中的unittest模块。 1、unittest 模块 主要使用unittest.TestCase类。继承该类,编写成员方法作为测试用例。类成员方法(测试用例)名以test作为前缀。 import unittest class TestCls(unittest.TestCase)…

java treemap_Java TreeMap ceilingKey()方法与示例

java treemapTreeMap类ceilingKey()方法 (TreeMap Class ceilingKey() method) ceilingKey() method is available in java.util package. ceilingKey()方法在java.util包中可用。 ceilingKey() method is used to return the lower-key element larger than or equal to the g…

Mysql 死锁的详细分析方法

用数据库的时候,偶尔会出现死锁,针对我们的业务系统,出现死锁的直接结果就是系统卡顿、客户找事儿,所以我们也在想尽全力的消除掉数据库的死锁。出现死锁的时候,如果只是想解锁,用show full processlist看下…

c语言sort_merge_sort

归并排序归并排序(Merge Sort)是建立在归并操作上的一种有效,稳定的排序算法,该算法是采用分治法(Divide and Conquer)的一个非常典型的应用。将已有序的子序列合并,得到完全有序的序列&#xf…

stringreader_Java StringReader close()方法与示例

stringreaderStringReader类close()方法 (StringReader Class close() method) close() method is available in java.io package. close()方法在java.io包中可用。 close() method is used to close this StringReader stream and free all system resources linked with the …

Python3中IO文件操作的常见用法

首先创建一个文件操作对象: f open(file, mode, encoding) file指定文件的路径,可以是绝对路径,也可以是相对路径 文件的常见mode: mode “r” # 只读 mode “w” # 只写 mode “a” # 追加 mode “r” #可以读写 正常情况…

Java OutputStream flush()方法与示例

OutputStream类flush()方法 (OutputStream Class flush() method) flush() method is available in java.io package. flush()方法在java.io包中可用。 flush() method is used to flush this OuputStream and force output bytes to be written out of any buffer. Let suppos…