将秒转换为yyyy-mm-dd hh:mm:ss PostgreSQL [英] Convert seconds to yyyy-mm-dd hh:mm:ss PostgreSQL

查看:111
本文介绍了将秒转换为yyyy-mm-dd hh:mm:ss PostgreSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to PostgreSQL sql and now working on an already existing database. I have a column called value in a table and it contains datetime stamp in seconds. So I am looking for way I can convert those seconds to yyyy-mm-dd hh:mm:ss in a Postgres database. I tried the following:

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




1444646136079是我想要转换的值
但出现以下错误:

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

错误:间隔字段值超出范围: 1444646136079秒

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


推荐答案

时间间隔不是时间戳。

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

The to_timestamp() function accepts seconds as an input and can convert that to a proper timestamp. I believe your 1444646136079 is in fact milli seconds, not seconds:

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

返回值:

2015-10-12 12:35:36

这篇关于将秒转换为yyyy-mm-dd hh:mm:ss PostgreSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆