Postgres:如何将 int 时间戳格式化为可读日期字符串? [英] Postgres: How do I format an int timestamp as readable date string?
本文介绍了Postgres:如何将 int 时间戳格式化为可读日期字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一列包含 unix 时间戳 - 一个代表自 纪元以来的秒数的整数一>.它们看起来像这样:1347085827
.如何在 SELECT 查询中将其格式化为人类可读的日期字符串?
Say I have a column that contains unix timestamps - an int representing the number of seconds since the epoch. They look like this: 1347085827
. How do I format this as a human-readable date string in my SELECT query?
推荐答案
Postgresql 有一个方便的内置函数:to_timestamp()
.只需将该函数包裹在您想要的列中即可:
Postgresql has a handy built-in function for this: to_timestamp()
. Just wrap that function around the column you want:
Select a, b, to_timestamp(date_int) FROM t_tablename
这篇关于Postgres:如何将 int 时间戳格式化为可读日期字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文