Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PostgreSQL格式时间戳,时区偏移量(澳大利亚/悉尼)为JSON/String_Postgresql_Timezone Offset_Timestamp With Timezone_To Char_To Json - Fatal编程技术网

PostgreSQL格式时间戳,时区偏移量(澳大利亚/悉尼)为JSON/String

PostgreSQL格式时间戳,时区偏移量(澳大利亚/悉尼)为JSON/String,postgresql,timezone-offset,timestamp-with-timezone,to-char,to-json,Postgresql,Timezone Offset,Timestamp With Timezone,To Char,To Json,我希望在Postgres中获得一个JSON对象,该对象显示澳大利亚/悉尼时区偏移的时间戳(+10:00或+11:00,在夏令时),例如,我希望JSON对象返回以下值: "2021-07-31T23:59:59.123456+10:00" "2021-01-31T23:59:59.123456+11:00" 但是当我使用to_json()或to_char()时,返回的时间戳值是UTC加上偏移量+00:00 select to_json(current

我希望在Postgres中获得一个JSON对象,该对象显示澳大利亚/悉尼时区偏移的时间戳(+10:00或+11:00,在夏令时),例如,我希望JSON对象返回以下值:

"2021-07-31T23:59:59.123456+10:00"   
"2021-01-31T23:59:59.123456+11:00"
但是当我使用to_json()或to_char()时,返回的时间戳值是UTC加上偏移量+00:00

select to_json(current_timestamp::timestamptz),
to_char(current_timestamp::timestamptz, 'YYYY-MM-DD"T"HH24:MI:SS:MSOF')
“2021-01-31T07:47:22.895185+00:00”
2021-01-31T07:47:22:895+00

我尝试添加“在时区'AEDT'”,但它会将时间戳值移动,并将偏移量保持在+00:00


谢谢。

到_json
格式根据会话的当前时区设置。我建议您首先将会话时区设置为
澳大利亚/悉尼

设置时区“澳大利亚/悉尼”;
选择to_json('2021-01-31T07:47:22.895+00'::timestamptz);

产生2021-01-31T18:47:22.895+11:00,我想这是您需要的。

不相关,但是:
current\u timestamp::timestamp
可以简化为
current\u timestamp