在Java开发中,很多时候我们为了方便会直接使用long型来保存时间,可以通过System.currentTimeMillis()或者是java.util.Date.getTime()来获取;取值为当前日期时间与1970-01-01相差的毫秒数;
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') current_date, (sysdate- to_date('1970-01-01','yyyy-mm-dd')) * 86400000 current_milli from dual;
CURRENT_DATE CURRENT_MILLI
------------------- -------------
2009-01-06 14:00:09 1231250409000
SQL> select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') current_date, (sysdate - 8 / 24 - to_date('1970-01-01', 'yyyy-mm-dd')) * 86400000 current_milli from dual;
CURRENT_DATE CURRENT_MILLI
------------------- -------------
2009-08-25 17:33:17 1251192797000
用简单的Java测试代码测试、结果显示完全匹配;Java代码如下:
[java] view plaincopy
Date date = new Date(1251192797000L); //2009-08-25 17:33:17
System.out.println(date);