時間關係轉換

2022-08-26 15:39:13 字數 1693 閱讀 1678

#標準庫time及datetime

import time

print(time.time())

print(time.timezone)#本地時間與世界時間差,秒為單位

print(time.sleep(1),123)#睡幾秒

print(time.gmtime(1541844509))#沒有引數為世界時間戳

print(time.localtime())#沒有引數為本地時間戳

print(time.localtime().tm_yday)

#print(help(time))

print(time.mktime(time.localtime()))

#print(help(time.mktime))

print(time.strftime('%y-%m-%d %h:%m:%s'))

print(time.strptime('2018-11-10 18:30:32','%y-%m-%d %h:%m:%s'))

z = time.mktime(time.strptime('2018-11-10 18:30:32','%y-%m-%d %h:%m:%s'))

print(z)

print(time.asctime())

print(time.ctime())

import datetime

print(datetime.datetime.now())

print(datetime.datetime.now()+datetime.timedelta(-3))#3天前的時間

print(datetime.datetime.now()+datetime.timedelta(hours=-3))#3小時前的時間

1541851708.6755588

-28800

none 123

time.struct_time(tm_year=2018, tm_mon=11, tm_mday=10, tm_hour=10, tm_min=8, tm_sec=29, tm_wday=5, tm_yday=314, tm_isdst=0)

time.struct_time(tm_year=2018, tm_mon=11, tm_mday=10, tm_hour=20, tm_min=8, tm_sec=29, tm_wday=5, tm_yday=314, tm_isdst=0)

3141541851709.0

2018-11-10 20:08:29

time.struct_time(tm_year=2018, tm_mon=11, tm_mday=10, tm_hour=18, tm_min=30, tm_sec=32, tm_wday=5, tm_yday=314, tm_isdst=-1)

1541845832.0

sat nov 10 20:08:29 2018

sat nov 10 20:21:12 2018

2018-11-10 20:21:12.877268

2018-11-07 20:21:12.877268

2018-11-10 17:21:12.877268

時間關係函式

viminfo檔案中匹配 檔案中的某行 1590632880 0 string temp buf 將上述舉例行存入temp std smatch sma std regex rex d 0 bool ret std regex search temp,sma,rex tm t tm time t t...

時間戳轉換時間

遇到兩個問題,第一是當前時間轉化為時間戳,第二是獲取的當前時間和系統的時間相差8個小時 一,轉化的方法為 nsstring timesp nsstring stringwithformat d long localedate timeintervalsince1970 nslog timesp ti...

各種時間格式轉換 時間戳轉換

1 後端介面返回時間格式轉換成時間戳 例 2021 02 15t09 33 08.694 0000 方案1 const time 2021 02 15t09 33 08.694 0000 時間戳 new date time gettime 方案2 安裝moment import moment fro...