postgresql - 时区感知 date_trunc 函数

标签 postgresql timezone timezone-offset

下面的查询

SELECT the_date FROM date_trunc('day', timestamp with time zone 
       '2001-01-1 00:00:00+0100') as the_date

结果

the_date
2000-12-31 00:00

有没有办法告诉 date_trunc 根据输入的时区进行日/月/年转换?

预期输出为:2001-01-1 00:00+0100

最佳答案

您需要指定要显示的时区

select
    date_trunc(
        'day',
        timestamp with time zone '2001-01-1 00:00:00+0100' at time zone '-02'
    ) as the_date;
      the_date       
---------------------
 2001-01-01 00:00:00

AT TIME ZONE

关于postgresql - 时区感知 date_trunc 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24040039/

相关文章:

cakephp - 设置时区不会更改CakePHP 3.x中的显示时间

c# - 为什么 C# 没有检测到 1970/1/1 处于 BST 之下?

javascript - Angular JS - 提交到 $http 时的日期更改 - 时区问题

sql - 使用postgresql数据库在liquibase中设置初始值

django - 南方不为第三方安装的应用程序创建表

datetime - iCAL DTSTART 和 DTEND 格式混淆。应该很容易回答

c# - 如何将 UTC 转换为澳大利亚东部夏令时间 (AEDT)?

postgresql - 如何删除 Postgresql 中的存储过程?

postgresql - 哪个更有效,在分区上选择 array_agg,还是选择数组(子查询)?

php - 如何在 PHP 中获取时区的名称和缩写?