Alex Rivera | Logout

Oracle equaivalent of java System.currentTimeMillis()?

Asked 2010-05-13T06:07:18.087
13

I want to be able to store the current time in milliseconds in an Oracle number field. How do I do this via a query?

select systimestamp from dual; 

returns the actual timestamp. Is there anyway that I can convert this into milliseconds the same way Java's System.currentTimeMillis() does?

Edit
Report

1 Answer

3
  • DB timezone agnostic
  • with milliseconds
  • works in XE
    function current_time_ms
        return number
    is
        out_result number;
    begin
        select extract(day from(sys_extract_utc(systimestamp) - to_timestamp('1970-01-01', 'YYYY-MM-DD'))) * 86400000 
            + to_number(to_char(sys_extract_utc(systimestamp), 'SSSSSFF3'))
        into out_result
        from dual;
        return out_result;
    end current_time_ms;
answered 2011-08-30T15:07:38.507

Your Answer