1. 程式人生 > >python3 5月26日 time模塊常用時間轉換

python3 5月26日 time模塊常用時間轉換

alt 常用 family tro 本地 import -s form ftime

import time

獲取當前時間:

指定字符串格式:time.strftime("%Y-%m-%d %H:%M:%S")

當前時間戳:time.time()

當前時間元組格式:time.localtime()

字符串轉時間格式

將時間字符串轉按指定格式換為元組<class ‘time.struct_time‘>
time.strptime(“字符串”,format("%Y-%m-%dT%H:%M:%SZ"))

將時間格式轉換為時間戳:
time.mktime(‘class ‘time.struct_time’格式的元組) #將時間格式元組轉換為時間戳 <class ‘float‘>

time.gmtime(時間戳)將時間戳轉換為UTC時間元組
time.localtime(時間戳)將時間戳轉換為本地時區的時間元組

time.ctime(‘時間戳’)將時間戳轉換為字符串(本地時間) 如Sat May 26 21:11:24 2018

time.asctime(時間元組)將時間格式元組轉換為 特定固定格式字符串 如Sat May 26 21:11:24 2018

 

python3 5月26日 time模塊常用時間轉換