如何将Unix纪元转换为时间戳 [英] How to convert Unix epoch to a timestamp

查看:155
本文介绍了如何将Unix纪元转换为时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Postgresql bot的新手,而不是sql。我有一个需要从中读取值的表,其中一列是unix时间戳,我想将其转换为更易读的格式,因此我发现了这一点:

I am new to postgresql bot not to sql in general. I have a table that I need to read values from, on of the columns is a unix timestamp that I want to convert in to a more human readable format thus I found this:

SELECT lt,dw,up,to_char(uxts, 'YYYY-MM-DD HH24:MI:SS') 
from products;

但这会产生错误:
错误:多个小数点

But that produces an error: ERROR: multiple decimal points

我在这里迷路了。我相信有人可以教我如何做。该文档对我来说还不清楚。 PostgreSQL 9.5是数据库。

I am lost here. I am sure someone can show me how to do it. The documentation isn't that clear to me. Postgresql 9.5 is the database.

推荐答案

to_char()转换数字,日期或时间戳记转换为字符串,而不是相反。

to_char() converts a number, date or timestamp to a string, not the other way round.

您要 to_timestamp()


转换Unix时期(自1970年以来的秒数) -01-01 00:00:00 + 00)时间戳

Convert Unix epoch (seconds since 1970-01-01 00:00:00+00) to timestamp






在您的列上应用该函数


So just apply that function on your column

SELECT lt,dw,up,to_timestamp(uxts) as uxts 
from products;

这假定uxts是某种数字数据类型( integer bigint 双精度

This assumes that uxts is some kind of number data type (integer, bigint or double precision)

这篇关于如何将Unix纪元转换为时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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