postgresql Postgres:如何将 int 时间戳格式化为可读日期字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12328817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgres: How do I format an int timestamp as readable date string?
提问by culix
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?
假设我有一列包含 unix 时间戳 - 一个 int 表示自epoch以来的秒数。他们是这样的:1347085827
。如何在我的 SELECT 查询中将其格式化为人类可读的日期字符串?
回答by culix
Postgresql has a handy built-in function for this: to_timestamp()
. Just wrap that function around the column you want:
Postgresql 有一个方便的内置函数:to_timestamp()
. 只需将该函数环绕您想要的列:
Select a, b, to_timestamp(date_int) FROM t_tablename