Search code examples
javasqloraclesysdate

get current database sysdate using java instead of sql


it is possible to get the current system date of oracle database using this query,

SELECT sysdate FROM dual;

select (sysdate - to_date('1970-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS')) * 86400 unix_ts from dual;

which returns 19-DEC-12 and 1355949236.999999999999999999999999999998 format respectively.

what if i need it to get it from java perspective and in unix_time format?

1) what is the library name?

e.g.:

import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import com.portal.pcm.fields.TmFldRefundIndLastModDate;

2) how to call it?

e.g.:

if(sysdate >= a_date_which_is_in_unix_time_format){...}

Thank you.


Solution

  • I think you want:

    long seconds = new java.util.Date().getTime() / 1000;
    

    See the docs for Date#getTime()