Oracle中date与long相互转换

Oracle中保存日期时,有时会保存long型的数据,固定长度是13位,是用当前时间减去1970-01-01,再换算成毫秒得到的结果。


date转long 

select (sysdate- to_date('1970-01-01','yyyy-mm-dd'))* 24*60*60*1000 current_milli from dual

select to_number(to_date('2005-03-29 12:30:45', '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

long转date

select  to_date('1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss') + 1241450728000/1000/24/60/60  from  dual

select to_date('1970-01-01 08','yyyy-mm-dd hh24') + 1397059632/60/60/24 as push_time from dual

select to_char(to_date('1970-01-01 08','yyyy-mm-dd hh24') +1397059632/60/60/24 , 'yyyy-mm-dd hh24:mi:ss') datestr from dual

你可能感兴趣的:(sql,Date,long)