在java中,调用System.currentTimeMillis()获取到系统当前时间的UNIX时间戳是以毫秒为单位的,但是ORACLE中,如果需要将时间戳转为时间或者时间字符串,必须先除以1000,该互转如下。
JAVA获取时间戳:long time = System.currentTimeMillis();
ORACLE转换为时间:
select ( to_date('19700101', 'yyyymmdd') + 1508138701256 / 86400 / 1000 +
to_number(substr(tz_offset(sessiontimezone), 1, 3)) / 24 ) as datetime from dual;
ORACLE转换为格式时间字符串:
select to_char(to_date('19700101', 'yyyymmdd') + 1508138701256 / 86400 / 1000 +
to_number(substr(tz_offset(sessiontimezone), 1, 3)) / 24, 'yyyymmdd hh24:mi:ss')
as datetime from dual;
ORACEL根据日期生成UNIX时间戳,in_date 为oracle中俄日期时间入参:
select ( ( in_date - to_date('19700101','yyyymmdd') ) * 86400 -
to_number( substr( tz_offset(sessiontimezone),1,3) )*3600 ) as datetime
from dual;