对于以下两个查询,如何在 UTC+02(相同时区)中显示时间戳?

How can I have timestamp displayed in UTC+02 (same timezone) for both the queries below?

我的第一个查询是:

SELECT distinct wfc_request_job_id,wfc_request_job_info,
               replace(iso_cc,';',' ') as "iso_cc",to_char(wfc_request_start_ts,'yyyy-MM-dd HH:mm:ss') as ts,
               sent_message_count,
               (link_object_count + poi_object_count + point_address_object_count) as request_object_count 
FROM wfc_request_job 
where 
wfc_request_job_id=173526;

此 returns 为 2015-08-16 03:08:59

第二个查询:

SELECT wfc_request_job_id,wfc_request_start_ts,wfc_request_end_ts,replace(iso_cc,';',' ') as "iso_ccs",sent_message_count,wfc_queue_name 
FROM wfc_request_job
where 
to_char(wfc_request_start_ts,'YYYY-MM-DD') >= to_char(to_date('08/16/2015','MM/DD/YYYY'),'YYYY-MM-DD') 
and to_char(wfc_request_start_ts,'YYYY-MM-DD') <= to_char(to_date('08/16/2015','MM/DD/YYYY'),'YYYY-MM-DD')
order by wfc_request_job_id desc

这个return上面提到的job id的s ts为 - "2015-08-16 15:58:59.809+02"

如何在 UTC+02 中进行两个查询 return ts - 即相同时区

wfc_request_start_ts的数据类型是 - timestamp with timezone

我将查询更改为 HH24:MI:SS 格式,但这没有帮助。请注意,使用这些查询的网络应用程序将在德国和美国打开。

根据 postgresql 手册 to_char 有用于 Date/Time 格式化的 TZ(和 OF 从 v9.4 开始)模板模式。

因此在查询中需要添加

postgres=# select to_char(now(),'yyyy-MM-dd HH24:mm:ss TZ');
        to_char         
------------------------
 2015-08-19 12:08:56 CEST
(1 row)

此外,请确保在转换时指定时区 所以改为

to_date('08/16/2015','MM/DD/YYYY')

使用

TIMESTAMP WITH TIME ZONE '2015-08-16 00:00:00+02';

在第二个查询中。