我的数据库中有text
个值:
Sun Nov 11 2018 23:35:56 GMT+0000 (UTC)
Sun Nov 11 2018 23:35:57 GMT+0600 (Novosibirsk Standard Time)
我希望将它们转换为ISO字符串:
2018-11-11T23:35:56.000Z
2018-11-11T17:35:57.000Z
这对于JS很简单:
const date = new Date('Sun Nov 11 2018 23:35:57 GMT+0600 (Novosibirsk Standard Time)');
console.log(date.toISOString()); // 2018-11-11T17:35:57.000Z
但是如何在PostgreSQL中做到这一点?
这会产生关于时区的错误:
select 'Sun Nov 11 2018 23:35:57 GMT+0600 (Novosibirsk Standard Time)'::timestamptz
这丢失了有关TZ的信息,因为to_timestamp不支持TZ格式令牌:
select to_timestamp('Sun Nov 11 2018 23:35:57 GMT+0600 (Novosibirsk Standard Time)', 'Dy Mon DD YYYY HH24 MI SS');