一、将时间格式转换为时间戳格式
select (to_date('2024-08-02 15:00:00', 'yyyy-mm-dd hh24:mi:ss') - to_date( '1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss')) * 24 * 60 * 60 * 1000 AS timestamps from dual;
-- 1722582000000
二、将时间戳格式转为时间格式
-- 如果时间戳长度为13位
select to_char( 1722582000000 / (1000*60*60*24) + to_date('1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss' ) as datetime from dual;
-- 2024-08-02 15:00:00
-- 如果时间戳长度为10位
select to_char( 1722582000 / (60*60*24) + to_date('1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss' ) as datetime from dual;
-- 2024-08-02 15:00:00
三、将Date或Timestamp日期转为字符串
select to_char(datetimes,'yyyy-mm-dd hh24:mi:ss') as str_datetime from dual;
四、将字符串转为日期
select to_date('2024-08-02 15:00:00','yyyy-mm-dd hh24:mi:ss') as datetime from dual;
标签:00,ss,dd,mi,yyyy,mm,时间,Oracle,格式
From: https://blog.csdn.net/promise524/article/details/140870823