简体   繁体   English

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

[英]Convert seconds to yyyy-mm-dd hh:mm:ss PostgreSQL

I am new to PostgreSQL sql and now working on an already existing database.我是 PostgreSQL sql 的新手,现在正在处理一个已经存在的数据库。 I have a column called value in a table and it contains datetime stamp in seconds.我在表中有一个名为 value 的列,它包含以秒为单位的日期时间戳。 So I am looking for way I can convert those seconds to yyyy-mm-dd hh:mm:ss in a Postgres database.所以我正在寻找可以在 Postgres 数据库中将这些秒数转换为 yyyy-mm-dd hh:mm:ss 的方法。 I tried the following:我尝试了以下方法:

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: 1444646136079 是我想转换的值但我收到以下错误:

ERROR: interval field value out of range: "1444646136079 second"错误:间隔字段值超出范围:“1444646136079 秒”

An interval is not a "timestamp". interval不是“时间戳”。

The to_timestamp() function accepts seconds as an input and can convert that to a proper timestamp. to_timestamp()函数接受秒作为输入,并且可以将其转换为适当的时间戳。 I believe your 1444646136079 is in fact milli seconds, not seconds:我相信你的 1444646136079 实际上是毫秒,而不是秒:

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

returns:返回:

2015-10-12 12:35:36

You can try it too -你也可以试试——

select to_date(to_timestamp(1344646136069 / 1000)::TEXT, 'yyyy-mm-dd HH24:MI:SS');

select to_date(to_timestamp(1344646136069 / 1000)::TEXT, 'YYYY-MM-DD HH:MI:SS');

Output :输出

11.08.2012 00:00:00
11.08.2012 00:00:00

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何转换为日期时间YYYY-MM-DD HH:mi:ss - How to Convert to Datetime YYYY-MM-DD HH:mi:ss 如何在 Postgres 中将 YYYY-MM-DDTHH:mm:ss.SSSZ 时间戳转换为 YYYY-MM-DD HH:mm:ss - How to convert YYYY-MM-DDTHH:mm:ss.SSSZ timestamp to YYYY-MM-DD HH:mm:ss in Postgres 在Postgresql中存储格式为yyyy-mm-dd hh:mm:ss的日期的数据类型 - Datatype to store date of format yyyy-mm-dd hh:mm:ss in postgresql 以oracle和PostgreSQL查询以yyyy-MM-dd'T'HH:mm:ss.SSSZ格式打印日期 - Query to print date in yyyy-MM-dd'T'HH:mm:ss.SSSZ format in oracle and postgresql 将任何输入时间戳 ex (4/25/2021 20.01.42) 转换为正确的 Postgres 时间戳 (YYYY-MM-DD HH12:MI:SS) - Convert any input timestamp ex (4/25/2021 20.01.42) to Correct Postgres TimeStamp (YYYY-MM-DD HH12:MI:SS) PostgreSQL 9.3:将DD-MM-YYYY转换为YYYY-MM-DD - PostgreSQL 9.3 : Convert `DD-MM-YYYY` into `YYYY-MM-DD` Rails转换yyyy-MM-dd'T'HH:mm:ssZ至今 - Rails Convert yyyy-MM-dd'T'HH:mm:ssZ To date PostgreSQL - 如何将数字字段中的秒数转换为 HH:MM:SS - PostgreSQL - How to convert seconds in a numeric field to HH:MM:SS Django DateTimeField 时间戳值的格式无效。 它必须是 YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] 格式 - Django DateTimeField Timestamp value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format Sequelize 如何将日期格式化为 YYYY-MM-DD HH:mm:ss 并将列保持为蛇形 - Sequelize How do you format date to YYYY-MM-DD HH:mm:ss and keep the columns as snake case
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM