Postgres:如何将int时间戳格式化为可读日期字符串?

cul*_*lix 14 postgresql

假设我有一个包含unix时间戳的列 - 一个表示自纪元以来秒数的int .它们看起来像这样:1347085827.如何在SELECT查询中将其格式化为人类可读的日期字符串?

cul*_*lix 20

Postgresql有一个方便的内置函数:to_timestamp().只需将该函数包装在您想要的列周围:

Select a, b, to_timestamp(date_int) FROM t_tablename
Run Code Online (Sandbox Code Playgroud)

  • 如果要输出特定的日期/时间/时间戳格式,请使用`to_char`. (3认同)