PostgreSQL:如何从Unix纪元转换为“时间戳”,直到分钟?

im9ewurl  于 2023-03-01  发布在  PostgreSQL
关注(0)|答案(2)|浏览(216)

我如何从Unix转换为“时间戳”直到分钟?
例如,1672718268 -〉2023年1月3日06:57更新:格式-非字符串
我尝试使用函数:

  • 至时间戳(修改后的时间)::日期+日期截断(“小时”,修改后的时间)+日期部分(“分钟”,修改后的时间)::int
  • 至时间戳(至时间戳(修改后的时间)::时间戳,'YYYY-MM-DD HH 24:MI')
  • 从表中提取(从修改的时间开始)
  • date_trunc('minute',to_timestamp(修改后的时间)::时间戳)

an example of desired output

0wi1tuuw

0wi1tuuw1#

select to_char(date_trunc('minutes', to_timestamp(1672718268)), 'YYYY-MM-DD HH24:MI');
     to_char      
------------------
 2023-01-02 19:57
toiithl6

toiithl62#

这应该行得通:

SELECT to_char(to_timestamp(1672718268), 'YYYY-MM-DD HH24:MI');

结果将是一个字符串,而不是时间戳,因为时间戳也有秒。
对于日期,将时间戳转换为日期:

SELECT cast(to_timestamp(1672718268) as date);

相关问题