python 示例_帶有示例的Python date timetuple()方法

python 示例

Python date.timetuple()方法 (Python date.timetuple() Method)

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

date.timetuple()方法用于操作模塊datetime的日期類的對象。

It is an instance method which means that it works on an instance of the class. It returns a time.struct_time which is an object with a named tuple interface containing nine elements.

這是一個實例方法,這意味著它可以在類的實例上工作。 它返回一個time.struct_time ,它是一個具有包含9個元素的命名元組接口的對象。

Following values are present in time.struct_time object:

time.struct_time對象中存在以下值:

IndexAttributeValue
0tm_year(for example, 1993)
1tm_monrange [1, 12]
2tm_mdayrange [1, 31]
3tm_hourrange [0, 23]
4tm_minrange [0, 59]
5tm_secrange [0, 61]
6tm_wdayrange [0, 6], Monday is 0
7tm_ydayrange [1, 366]
8tm_isdst0, 1 or -1; see below
N/Atm_zoneabbreviation of timezone name
N/Atm_gmtoffoffset east of UTC in seconds
指數 屬性
0 tm_year (例如1993)
1個 tm_mon 范圍[1,12]
2 tm_mday 范圍[1,31]
3 tm_hour 范圍[0,23]
4 tm_min 范圍[0,59]
5 tm_sec 范圍[0,61]
6 tm_wday 范圍[0,6],星期一為0
7 tm_yday 范圍[1,366]
8 tm_isdst 0、1或-1; 見下文
不適用 tm_zone 時區名稱的縮寫
不適用 tm_gmtoff 以秒為單位偏移UTC以東

A date timetuple is equivalent to,

日期時間元組等于

    time.struct_time((d.year, d.month, d.day, 0, 0, 0, d.weekday(), yday, -1))

Since it is a date object, time values are missing because of which those attributes are set to zero(index- 3,4,5). As date object is naive, the timezone information are also missing.

由于它是一個日期對象,因此缺少時間值,因此這些屬性設置為零(索引3、4、5)。 由于日期對象太幼稚,因此時區信息也丟失了。

Module:

模塊:

    import datetime

Class:

類:

    from datetime import date

Syntax:

句法:

    timetuple()

Parameter(s):

參數:

  • None

    沒有

Return value:

返回值:

The return type of this method is a time.struct_time object which contains date information.

此方法的返回類型是time.struct_time對象,其中包含日期信息。

Example:

例:

## Python program explaining the 
## use of date class instance methods
from datetime import date
## Creating an instance
x = date(2020, 4, 29)
print("Current date is:", x)
print()
d = x.timetuple()
print("The tuple of the date object", d)
print()
print("We can also access individual elements of this tuple")
for i in d:
print(i)

Output

輸出量

Current date is: 2020-04-29
The tuple of the date object time.struct_time(tm_year=2020, tm_mon=4, tm_mday=29, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=120, tm_isdst=-1)
We can also access individual elements of this tuple
2020
4
29
0
0
0
2
120
-1

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

python 示例

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

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

相關文章

WebC.BBS 項目參與新人必讀

開發環境: 采用Visual Studio 2010,MVC版本采用Asp.Net MVC3,數據庫采用Sql2005 2008,擴展技術包括jQuery。 SVN的相關信息: SVN-Url:svn://svn.cyqdata.com/project_bbs 賬戶申請:請將自己的密碼發給組長,…

第四章 字典

第四章 字典{鍵:值,名字:電話號碼} 映射:通過名稱來訪問其各個值的數據結構 列表:將一系列值組合成數據結構并通過編號來訪問各個值 字典是Python中唯一的內置映射類型,其中的值不按順序排列,而是存儲在鍵下 鍵可能是數、字符串…

利用梯度下降法求解一元線性回歸和多元線性回歸

文章目錄原理以及公式【1】一元線性回歸問題【2】多元線性回歸問題【3】學習率【4】流程分析(一元線性回歸)【5】流程分析(多元線性回歸)歸一化原理以及每種歸一化適用的場合一元線性回歸代碼以及可視化結果多元線性回歸代碼以及可…

linux x64 asm 參數傳遞,NASM匯編學習系列(1)——系統調用和參數傳遞

0. 說明本學習系列代碼幾乎完全摘自:asmtutor.com,如果英文可以的(也可以用谷歌瀏覽器翻譯看),可以直接看asmtutor.com上的教程系統環境搭建:(我用的是ubuntu18.04.4 server,安裝gcc、g)sudo apt install nasmsudo apt…

Javascript之創建對象(原型模式)

我們創建的每個函數都有一個prototype(原型)屬性,這個屬性是一個指針,指向一個對象,它的用途是包含可以有特定類型的所有實例共享的屬性和方法。 prototype就是通過構造函數而創建的那個對象的原型對象。使用原型的好處就是可以讓所有對象實例…

treeset java_Java TreeSet pollLast()方法與示例

treeset javaTreeSet類pollLast()方法 (TreeSet Class pollLast() method) pollLast() method is available in java.util package. pollLast()方法在java.util包中可用。 pollLast() method is used to return the last highest element and then remove the element from thi…

第五章 條件、循環及其他語句

第五章 條件、循環及其他語句 再談print和import print現在實際上是一個函數 1,打印多個參數 用逗號分隔,打印多個表達式 sep自定義分隔符,默認空格 end自定義結束字符串,默認換行 print("beyond",yanyu,23)#結果為…

兩種方法將Android NDK samples中hello-neon改成C++

一、第一種方法:1.修改helloneon.c 中代碼 a.將 char* str; 改為 char str[512] {0}; b.將 asprintf(&str, "FIR Filter benchmark:\nC version : %g ms\n", time_c); 改為 sprintf(str, "FIR Filter benchmark:\nC ve…

【視覺項目】【day6】8.26關于matchTemplate()以及NCC的思考整理

NCC與matchTemplate()函數中match_method TM_CCOEFF_NORMED是否一樣? 先看公式: TM_CCOEFF_NORMED NCCTM_CCOEFF_NORMED:歸一化的相關性系數匹配方法 NCC:normalized cross correlation:歸一化互相關系數 公式是一樣的。 參考: 模板匹配的幾…

linux待機流程,Linux睡眠喚醒機制--Kernel態

一、對於休眠(suspend)的簡單介紹 在Linux中,休眠主要分三個主要的步驟: 1) 凍結用戶態進程和內核態任務2) 調用注冊的設備的suspend的回調函數, 順序是按照注冊順序3) 休眠核心設備和使CPU進入休眠態, 凍結進程是內核把進程列表中所有的進程的狀態都設置為停止,並且保存下…

strictmath_Java StrictMath log1p()方法與示例

strictmathStrictMath類log1p()方法 (StrictMath Class log1p() method) log1p() method is available in java.lang package. log1p()方法在java.lang包中可用。 log1p() method is used to return (the logarithm of the sum of the given argument and 1 like log(1d) in th…

第六章 抽象

第六章 抽象 自定義函數 要判斷某個對象是否可調用,可使用內置函數callable import math x 1 y math.sqrt callable(x)#結果為:False callable(y)#結果為:True使用def(表示定義函數)語句,來定義函數 …

HTTP 狀態代碼

如果向您的服務器發出了某項請求要求顯示您網站上的某個網頁(例如,當用戶通過瀏覽器訪問您的網頁或在 Googlebot 抓取該網頁時),那么,您的服務器會返回 HTTP 狀態代碼以響應該請求。 此狀態代碼提供了有關請求狀態的信…

TensorFlow的可訓練變量和自動求導機制

文章目錄一些概念、函數、用法TensorFlow實現一元線性回歸TensorFlow實現多元線性回歸一些概念、函數、用法 對象Variable 創建對象Variable: tf.Variable(initial_value,dtype)利用這個方法,默認整數為int32,浮點數為float32,…

linux samba安裝失敗,用aptitude安裝samba失敗

版本:You are using Ubuntu 10.04 LTS- the Lucid Lynx - released in April 2010 and supported until April 2013.root下執行aptitude install sambaReading package lists... DoneBuilding dependency treeReading state information... DoneReading extended st…

django第二個項目--使用模板做一個站點訪問計數器

上一節講述了django和第一個項目HelloWorld,這節我們講述如何使用模板,并做一個簡單的站點訪問計數器。 1、建立模板 在myblog模塊文件夾(即包含__init__.py的文件夾)下面新建一個文件夾templates,用于存放HTML模板,在…

strictmath_Java StrictMath log10()方法與示例

strictmathStrictMath類log10()方法 (StrictMath Class log10() method) log10() method is available in java.lang package. log10()方法在java.lang包中可用。 log10() method is used to return the logarithm of the given (base 10) of the given argument in the method…

30、深入理解計算機系統筆記,并發編程(concurrent)(2)

1、共享變量 1)線程存儲模型 線程由內核自動調度,每個線程都有它自己的線程上下文(thread context),包括一個惟一的整數線程ID(Thread ID,TID),棧,棧指針,程序…

PostgreSQL在何處處理 sql查詢之十三

繼續: /*--------------------* grouping_planner* Perform planning steps related to grouping, aggregation, etc.* This primarily means adding top-level processing to the basic* query plan produced by query_planner.** tuple_fraction i…

【視覺項目】基于梯度的NCC模板匹配代碼以及效果

文章目錄流程分析工程代碼【1】NCC代碼【Ⅰ】sttPxGrdnt結構體【Ⅱ】sttTemplateModel模板結構體【Ⅲ】calcAccNCC計算ncc系數函數【Ⅳ】searchNcc NCC模板匹配函數【Ⅴ】searchSecondNcc 二級搜索:在某一特定點周圍再以步進為1搜索【2】測試圖轉外輪廓【Ⅰ】孔洞填…