postgresql 将数字转换为日期和格式

Ari*_*rif 3 postgresql type-conversion to-date

我的日期字段在 postgresql 中为数字,日期中的值类似于 1401710352000,当我尝试使用 to_timestamp(date) 将其转换时,我得到相应的时间戳为“46388-06-07 10:40:00+00 ”

我试图用谷歌搜索它,我发现了关于如何在 postgresql 中进行不同类型转换的非常有用的函数,但我找不到如何将数字日期转换为适当的可读格式。如果有人能告诉我如何将数字日期字段转换为时间戳/日期可读格式,我会很感激

沙阿

mu *_*ort 9

来自精美手册

to_timestamp(double precision)
带时区的时间戳
将 Unix 纪元转换为时间戳

Unix 纪元以秒为单位,但看起来您的数值以毫秒为单位。如果我们固定单位,那么我们会得到一些看起来合理的东西:

=> select to_timestamp(1401710352000::numeric/1000);
      to_timestamp      
------------------------
 2014-06-02 04:59:12-07
Run Code Online (Sandbox Code Playgroud)

因此,您可能只需要在调用to_timestamp.