postgresql - 将秒数转换为 yyyy-mm-dd hh :mm:ss PostgreSQL

标签 postgresql date datetime

我是 PostgreSQL sql 的新手,现在正在处理一个已经存在的数据库。我在表中有一个名为 value 的列,它包含以秒为单位的日期时间戳。所以我正在寻找将这些秒数转换为 Postgres 数据库中的 yyyy-mm-dd hh:mm:ss 的方法。我尝试了以下方法:

SELECT  TO_CHAR('1444646136079 second'::interval, 'yyyy-mm-dd HH24:MI:SS')

1444646136079 is the value I would like to convert But I am getting the following error:

ERROR: interval field value out of range: "1444646136079 second"

最佳答案

interval 不是“时间戳”。

to_timestamp() 函数接受秒作为输入并将其转换为适当的时间戳。我相信你的 1444646136079 实际上是 milli 秒,而不是秒:

select to_char(to_timestamp(1444646136079 / 1000), 'yyyy-mm-dd HH24:MI:SS')

返回:

2015-10-12 12:35:36

关于postgresql - 将秒数转换为 yyyy-mm-dd hh :mm:ss PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33276366/

相关文章:

json - Postgres 集群 (citus) : Range Query on nested jsonb column

php - 如何获取 GMT+01 :00 with php

java - 解析日期时出现异常

c# - 将日期转换为正确的格式

python - 渲染文本日历

postgresql - 如何正确取消嵌套两个数组

javascript - SEQUELIZE - 如何获取所有关联对象?

postgresql - 使用 PostgreSQL Java/JDBC Copy API 进行批量插入的经验

PHP 从输入字段中获取文字年、月、日

mysql - 在 SQL 中选择给定时间之前的所有行