时间转换为时间戳
- 2021-12-28 15:43:57 格式的转换为时间戳
select (to_date('2021-12-28 15:43:57', 'yyyy-mm-dd hh24:mi:ss') -
to_date('1970-01-01 08:00:00', 'yyyy-mm-dd hh24:mi:ss')) * 86400000
from dual; --1640677437000
- 2021年12月28日 格式的转换为时间戳
select (to_date('2021年12月28日', 'yyyy"年"mm"月"dd"日"') -
to_date('1970-01-01 08:00:00', 'yyyy-mm-dd hh24:mi:ss')) * 86400000
from dual; --1640620800000
时间戳转换为时间
1.1640620800000 转换为时间
select to_char(1640620800000 / (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; --2021-12-28 00:00:00
字符串转换为时间戳
- 20211228000000 转换成时间戳
--如果是字符串,先转成时间,再转成时间戳
select (to_date(to_char(to_date('20211228000000', 'yyyymmddhh24miss'),
'yyyy-mm-dd hh24:mi:ss'),
'yyyy-mm-dd hh24:mi:ss') -
to_date('1970-01-01 08:00:00', 'yyyy-mm-dd hh24:mi:ss')) * 86400000
from dual; --1640620800000