How to write bigint (timestamp in milliseconds) value as timestamp in postgresql

后端 未结 3 1701
再見小時候
再見小時候 2021-02-07 10:44

I\'m trying to store in timestamp with timezone field my value. It is in milliseconds from 1970.

select TO_CHAR(TO_TIMESTAMP(1401432881230), \'DD/MM/YYYY HH24:MI:S

3条回答
  •  囚心锁ツ
    2021-02-07 11:03

    Unix timestamps measures time with seconds, and not milliseconds (almost everywhere, in PostgreSQL too).

    Therefore you need to call

    SELECT TO_TIMESTAMP(1401432881230 / 1000);
    

    If you want to preserve milliseconds, call with double precision:

    SELECT TO_TIMESTAMP(1401432881230::double precision / 1000);
    

提交回复
热议问题