偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Python stuct_time中模塊如何操作時(shí)間函數(shù)的方案

開發(fā) 后端
一下的文章就是對Python stuct_time中模塊如何操作時(shí)間的函數(shù)的兩種表現(xiàn)方式,以下是相關(guān)內(nèi)容的介紹,希望你會(huì)有所收獲。

 你知道Python stuct_time 中模塊如何使用整理提供N多種嗎?以下的文章就是通過對Python stuct_time 中模塊如何操作時(shí)間的函數(shù)的相關(guān)代碼去體現(xiàn)其的實(shí)際應(yīng)用方案,以下是文章的介紹。

一、Python stuct_time中模塊使用整理提供了各種操作時(shí)間的函數(shù)。一般有兩種表示的方式:

***種:以時(shí)間戳的方式(相對于1970.1.1 00:00:00 以秒計(jì)算的偏移量),時(shí)間戳是惟一

第二種:以數(shù)組的形式表示即(struct_time), 共有九個(gè)元素,分別表示,同一個(gè)時(shí)間戳的stuct_time會(huì)因?yàn)闀r(shí)區(qū)不同而不同。

時(shí)區(qū):夏令時(shí)區(qū)與UTC時(shí)區(qū)函數(shù)介紹:

  1. asctime()  
  2. asctime([tuple]) -> string    

 

將一個(gè)Python struct_time 轉(zhuǎn)換成字符串clock()該函數(shù)有兩個(gè)功能:在***次調(diào)用的時(shí)候,返回的是程序運(yùn)行的實(shí)際時(shí)間;(返回整個(gè)程序的總運(yùn)行時(shí)間值),以第二次之后的調(diào)用,返回的是自***次調(diào)用后,到這次調(diào)用的時(shí)間間隔。示例:

 

  1. import time  
  2. if __name__ == '__main__':  
  3. time.sleep(1)  
  4. print "clock1:%s" % time.clock()  
  5. time.sleep(1)  
  6. print "clock1:%s" % time.clock()  
  7. time.sleep(1)  
  8. print "clock1:%s" % time.clock()   

 

輸出:

 

  1. clock1:3.07301626324e-006  
  2. clock1:0.997576228264  
  3. clock1:1.99513653272   
  4. 1.1.3 sleep(seconds)  

 

線程推遲指定的時(shí)間運(yùn)行,經(jīng)過測試,單位為秒

  1. ctime(seconds)  
  2. ctime(seconds) -> string  

將一個(gè)時(shí)間戳Python stuct_time(默認(rèn)為當(dāng)前時(shí)間)轉(zhuǎn)換成一個(gè)時(shí)間字符串.示例:

 

  1. if __name__ == '__main__':  
  2. print time.ctime()  

 

輸出:

  1. Thu Mar 04 12:55:03 2010  
  2. 1.1.5 gmtime(...)  
  3. gmtime([seconds]) -> (tm_year, tm_mon, tm_day,
     tm_hour, tm_min,tm_sec, tm_wday, tm_yday, tm_isdst)  

9個(gè)參數(shù)值)將一個(gè)時(shí)間戳轉(zhuǎn)換成一個(gè)UTC時(shí)區(qū)(0時(shí)區(qū))的struct_time,如果seconds參數(shù)未輸入,則以當(dāng)前時(shí)間為轉(zhuǎn)換標(biāo)準(zhǔn)(數(shù)組類型的時(shí)間值)示例:

 

  1. if __name__ == '__main__':  
  2. print time.gmtime()   

時(shí)間元組輸出:

 

  1. (2010, 3, 4, 4, 58, 53, 3, 63, 0) 

 

返回的就是一個(gè)數(shù)組類型的數(shù)據(jù)。其中的含義分別為:

 

  1. (tm_year, tm_mon, tm_day, tm_hour, tm_min,tm_sec, tm_wday, tm_yday, tm_isdst) 

 

得到一個(gè)數(shù)組之后就可以這樣分割:print time.gmtime()[0] 得到***個(gè)元素值

【編輯推薦】

  1. Python socket編程在具體應(yīng)用中前兩個(gè)步驟的介紹
  2. 用python pylint檢查相關(guān)東西的操作方案詳解
  3. Python入門的相對路徑和絕對路徑詳解
  4. Python環(huán)境的實(shí)際應(yīng)用方案介紹與代碼詳解
  5. Python數(shù)據(jù)結(jié)構(gòu)創(chuàng)建的具體應(yīng)用方案詳解
       
     

 

責(zé)任編輯:佚名 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-03-16 18:59:47

Python模塊

2023-12-22 08:38:02

Pythondatetimetime

2010-03-16 10:00:37

Python函數(shù)

2010-03-16 20:27:52

Python模塊

2010-03-31 19:34:03

Oracle數(shù)據(jù)庫

2024-07-12 10:00:00

time模塊Python

2010-03-17 12:53:43

Python Libr

2021-03-07 08:46:54

Java時(shí)間操作Joda-Time

2010-03-17 10:58:47

Python學(xué)習(xí)筆記

2023-06-05 16:41:27

Python開發(fā)

2025-02-17 10:50:37

2023-01-05 16:36:55

2020-10-15 17:38:00

Time Wheel

2010-03-11 19:45:09

Python邏輯

2010-09-06 14:17:04

SQL函數(shù)

2025-02-12 10:51:51

2010-03-17 13:33:04

Python Libr

2010-03-23 18:38:26

Python os.m

2010-03-15 15:38:47

Python運(yùn)行

2010-03-26 11:00:55

Python嵌入CC++
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)