How to convert timestamp field to ISO 8601 string in a given time zone?

Viewed 5062

I have a "timestamp with time zone" field in a table.
I need to return is as iso 8601 string in a give time zone.
The closest thing that I managed to do is this:

select to_char(crtdate, 'YYYY-MM-DD"T"HH24:MI:SS.MSOF:"00"')  from t1

But it returns a timestamp in a system default time zone (UTC) i.e. something like this:

2017-07-12T02:46:26.194+00:00

while I need it be formatted for a specific time zone.
E.g.

2017-07-12T14:46:26.194+12:00

for "Pacific/Auckland".

Can someone please advise how this can be achieved?

we are on PG v 9.6.

Thank you,

1 Answers
Related