python: time
阿新 • • 發佈:2018-07-30
轉換 this 獲取 字符串 mon -- his %x struct time():獲取時間戳
gmtime() :換算成UTC時區的時間------->換成元組的形式
localtime():結果為UTC+8時區
gmtime() :換算成UTC時區的時間------->換成元組的形式
localtime():結果為UTC+8時區
例:獲取各個屬性
import time
x=time.localtime() #獲取當前時間
print(x)
print(x.tm_year)
x=time.localtime(19850803) #獲取過去某個時間
print(x.tm_year)
print(‘this is 1970 day:%d‘ %x.tm_yday)
time.mktime(x):#把元組形式轉換成時間戳
time.strftime("%Y-%m-%d %H:%M:%S") #把時間格式化
>>time.strftime("%Y-%m-%d %H:%M:%S")
>>2018-07-30 15:20:30
time.strptime("格式化的字符串") #轉換成strum_time
>>time.strptime(‘2018-07-30 15:28:30‘ ,‘%Y-%m-%d %H:%M:%S‘)
>>time.struct_time(tm_year=2018......)>>time.asctime()
>>‘Mon Jul 30 16:03:40 2018‘
python: time