oracle systimestamp (sysdate) to milliseconds

前端 未结 7 1256
予麋鹿
予麋鹿 2020-12-16 14:15

Could you provide implementation of stored function to get current systimestamp as milliseconds.
Something I can use like

select current_tim         


        
7条回答
  •  眼角桃花
    2020-12-16 14:52

    I've posted here some methods to convert timestamp to nanoseconds and nanoseconds to timestamp. These methods are not affected by time zones and have a nanosecond precision.

    You just need to adjust it to get milliseconds instead of nanoseconds.

    SELECT (EXTRACT(DAY FROM (
        SYSTIMESTAMP --Replace line with desired timestamp --Maximum value: TIMESTAMP '3871-04-29 10:39:59.999999999 UTC'
    - TIMESTAMP '1970-01-01 00:00:00 UTC') * 24 * 60) * 60 + EXTRACT(SECOND FROM
        SYSTIMESTAMP --Replace line with desired timestamp
    )) *  1000 AS MILLIS FROM DUAL;
    
    MILLIS
    1598434427263.027
    

提交回复
热议问题