python標準庫模組 time

2021-10-02 01:25:19 字數 973 閱讀 8499

"""

標準庫模組

time 時間

"""import time

# 1. 獲取當前時間戳(從2023年1月1日到現在經過的秒數)

print

(time.time())

# 1571724503.9006603

# 2. 獲取當前時間元組(年,月,日,時,分,秒,星期,一年的第幾天,與夏令時的偏移量)

# time.struct_time(tm_year=2019, tm_mon=10, tm_mday=22, tm_hour=14, tm_min=8, tm_sec=23, tm_wday=1, tm_yday=295, tm_isdst=0)

current_time_tuple = time.localtime(

)# 3.時間戳 --> 時間元組

current_time_tuple = time.localtime(

1571724503.9006603

)# 時間元組 --> 時間戳

print

(time.mktime(current_time_tuple)

)# 1571724503.0

# 4. 時間元組--> str

print

(time.strftime(

"%y/%m/%d %h:%m:%s"

,current_time_tuple)

)# 2019/10/22 14:31:53

print

(time.strftime(

"%y/%m/%d %h:%m:%s"

,current_time_tuple)

)# str --> 時間元組

print

(time.strptime(

"2019/10/22 14:31:53"

,"%y/%m/%d %h:%m:%s"

))

Python標準庫模組之time

import time 返回當前時間戳 1970年後經過的浮點秒數 時間戳是計算機世界中的時間 1555579087.1666212 print time.time 時間戳 時間元組 年,月,日,時,分,秒,星期,一年中的第幾天 夏令時 print time.localtime print time...

Python 標準庫大全之 time模組

time.strftime format,t time.sleep seconds 為python自帶標準庫 import time返回當前時間的時間戳 時間戳 timestamp 表示的是從1970年1月1日00 00 00開始按秒計算的偏移量.示例 print f 當前時間戳為 結果 當前時間戳...

模組 包 標準庫模組 time時間

定義 包含一系列資料 函式 類的檔案,通常以.py結尾。作用讓一些相關的資料,函式,類有邏輯的組織在一起,使邏輯結構更加清晰。有利於多人合作開發。匯入import 1.語法 import 模組名 import 模組名 as 別名 2.作用 將某模組整體匯入到當前模組中 3.使用 模組名.成員 fro...