You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PostgreSQL中如何将bigint类型时间戳转换为'DD-MM-YYYY'格式日期

解决方案

适配PostgreSQL环境写法(匹配你现有可运行语句的语法体系)

你已经通过to_timestamp完成了bigint转时间戳的步骤,只需额外调用to_char函数指定输出格式即可,最终语句如下:

select to_char(to_timestamp(last_downloaded/1000), 'DD-MM-YYYY') from stats;

格式符说明:

  • DD:输出两位数字的日期,不足两位自动补0
  • MM:输出两位数字的月份,不足两位自动补0
  • YYYY:输出四位数字的公历年份

其他常用数据库对应写法

如果你的运行环境不是PostgreSQL,可以参考对应语法:

  • MySQL:
select date_format(from_unixtime(last_downloaded/1000), '%d-%m-%Y') from stats;
  • SQL Server:
select format(dateadd(s, last_downloaded/1000, '1970-01-01'), 'dd-MM-yyyy') from stats;

内容的提问来源于stack exchange,提问作者naspy971

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 09:09:03