oracle 中时间类型 date 与 long 互转

原文:http://www.cnblogs.com/lambertwe/p/6116402.html

今天在项目中查询流程相关信息中,发现了其中的日期字段存的信息很奇怪,是一串数值,后面发现是long类型或者integer类型数值,然后就需要转行成相应的日期格式了。

在网上搜索一番得到解决:

1、date转long:

select sysdate, (sysdate-to_date('1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss'))* 24*60*60*1000 current_milli from dual;

2、long转date:

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

其中为什么是 1970-01-01 08:00:00  而不是 1970-01-01 00:00:00是因为我们是东八区呀。

 

posted @ 2017-08-11 18:10  山水花草  阅读(6797)  评论(1)    收藏  举报