Python默認起始時間爲1970-01-01 08:00:00
代碼驗證
import time
t = 0
print(time.localtime(t))
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)))
打印結果
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=8, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)
1970-01-01 08:00:00
相關應用
Python時間和毫秒互轉
https://blog.csdn.net/Yellow_python/article/details/104492510
import datetime
def str2date(s, fmt='%Y年%m月%d日'):
return datetime.datetime.strptime(s, fmt)
def date2float(d):
return d.timestamp()
def date2millisecond(d):
return int(date2float(d) * 1000)
def float2date(f):
return datetime.datetime.fromtimestamp(f)
def millisecond2date(ms):
return float2date(ms / 1000)
def date2str(d, fmt='%Y-%m-%d %H:%M:%S'):
return d.strftime(fmt)
Oracle時間和毫秒互轉
日期 -> 毫秒
SELECT
TO_NUMBER(
TO_DATE('2020-5-15 23:0:0','YYYY-MM-DD HH24:MI:SS')-TO_DATE('1970-01-01 8:0:0','YYYY-MM-DD HH24:MI:SS')
)*24*60*60*1000
FROM dual;
毫秒 -> 日期
SELECT
TO_CHAR(
1589554800000/(1000*60*60*24)+TO_DATE('1970-01-01 08:00:00','YYYY-MM-DD HH:MI:SS'),'YYYY-MM-DD HH24:MI:SS'
)FROM dual;