1
我需要將我的時間戳轉換爲時代值。我發現我的系統時區設置爲CET,我的my-sql數據庫也使用它。如何從本地時間戳獲取UTC時代值
我嘗試這樣做:
os.environ['TZ']='UTC'
epoch = int(time.mktime(time.strptime('2017-02-22 17:04:06', '%Y-%m-%d %H:%M:%S')))
print(epoch)
#Output: 1487779446 -> not the same compared to 1487779446000 (= '2017-02-22 17:04:06')
print(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(epoch/1000.)))
#Output: 01/18/1970 05:16:19 -> Not Correct!
# Timestamp: '2017-02-22 17:04:06'
print(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(1487779446000/1000.)))
#Output: 02/22/2017 16:04:06 -> Correct!
我CET想這也同樣的結果。我不明白爲什麼我會得到不同的價值觀。