【问题标题】:Getting incorrect date when converting epoch to timestamp将纪元转换为时间戳时获取不正确的日期
【发布时间】:2019-07-20 03:43:07
【问题描述】:

我有一个纪元格式的时间戳,如下所示:1551187548876。如果我使用https://www.epochconverter.com/ 将其转换为时间戳,我会得到正确的时间。

但是,如果我使用 PostgreSQL to_timestamp 将其转换为时间,我会得到以下信息:

select to_timestamp(1551187548876) from my_table;

51125-03-06 14:14:36+00

问题

如何将 epoch 1551187548876 转换为 PostgreSQL 中的时间戳?

【问题讨论】:

  • 除以 1000。

标签: sql postgresql epoch sql-timestamp


【解决方案1】:

我假设您拥有的纪元数是自纪元以来的毫秒秒数,而不是惯常的秒数。

尝试除以 1000:

select to_timestamp(1551187548.876);

        to_timestamp        
----------------------------
 2019-02-26 14:25:48.876+01
(1 row)

【讨论】:

    猜你喜欢
    • 2018-08-03
    • 2013-01-08
    • 1970-01-01
    • 2020-02-22
    • 1970-01-01
    • 2022-08-04
    • 2019-07-02
    • 2021-03-01
    • 2012-09-06
    相关资源
    最近更新 更多