将纪元转换为时间戳时获取错误的日期

问题描述 投票:1回答:1

我有一个epoch格式的时间戳,如下所示: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中的时间戳?

sql postgresql epoch sql-timestamp
1个回答
2
投票

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

尝试除以1000:

select to_timestamp(1551187548.876);

        to_timestamp        
----------------------------
 2019-02-26 14:25:48.876+01
(1 row)
© www.soinside.com 2019 - 2024. All rights reserved.