首页 > 解决方案 > 如何在 psql 中转换 unix_timestamp 整数?

问题描述

如何将 unix_timestamp 整数转换为可读文本中的时间。
如:

timestamp|integer|not null default 0
select timestamp from table limit 1; 
1541001600  

1541001600 应转换为Thu Nov 1 00:00:00 CST 2018

PostgreSQL 8.0.2

标签: sqlpostgresqlunix-timestamppostgresql-8.0

解决方案


您可以to_timestamp()在 postgresql 中使用。

select to_timestamp(1541001600) AT TIME ZONE 'CST';

参考链接了解更多详情

对于 8.0:

SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 1541001600 * INTERVAL '1 second';

推荐阅读