Вам нужно получить часовой пояс из строки, преобразовать его в смещение ECMAScript и использовать его для форматирования строки с требуемым смещением.
Уже есть ответы на SO, чтобы сделать выше, новот ответ в любом случае.
Например
/* Returns offset, uses match to allow for decimal seconds in timestamp
** @param {string} s - ECMAScript formatted datetime string with offset
** in the format YYYY-MM-DDTHH:mm:ss+/-HH:mm or Z
** @returns {string} - offset part of string, i.e. +/-HH:mm or Z
*/
function getOffset(s) {
return offset = (s.match(/z$|[+\-]\d\d:\d\d$/i) || [])[0];
}
/* Convert offset in +/-HH:mm format or Z to ECMAScript offset
** @param {string} offset - in +/-HH:mm format or Z
** @returns {number} - ECMSCript offset in minutes, i.e. -ve east, +ve west
*/
function offsetToMins(offset) {
// Deal with Z or z
if (/z/i.test(offset)) return 0;
// Deal +/-HH:mm
var sign = /^-/.test(offset)? '1':'-1';
var [h, m] = offset.slice(-5).split(':');
return sign * h * 60 + +m;
}
/* Format date with offset
** @param {Date} date - date to format
** @param {string} offset - ECMASCript offset string,
** e.g. -05:00, Z
** @returns {string} ISO 8601 formatted string with
** specified offset
*/
function adjustToOffset(date, offset) {
var o = offsetToMins(offset);
var d = new Date(+date);
d.setUTCMinutes(d.getUTCMinutes() - o);
return d.toISOString().replace('Z', offset);
}
// Source string
var s = '2018-12-30T20:00:00-05:00';
// Get offset
var offset = getOffset(s);
// Make sure it's ok
if (typeof offset == 'undefined') {
console.log('offset not found');
// Otherwise, show current time with specified offset
} else {
console.log(adjustToOffset(new Date(), offset));
}
Обратите внимание, что типичные смещения ISO 8601 не имеют двоеточия, то есть обычно они равны ± ЧЧмм.