const pad = num => ("0" + num).slice(-2);
const getFormattedDate = d => {
const tzOffsetMin = d.getTimezoneOffset(),
offsetHours = Math.floor(Math.abs(tzOffsetMin / 60)),
offsetMin = Math.abs(tzOffsetMin % 60);
let sign = "";
if (tzOffsetMin < 0) sign = "+"; // opposite of what we should think
else if (tzOffsetMin > 0) sign = "-";
// we could steal the time from the toString and replace / GMT/,""
return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}` +
`T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}` +
`${sign}${pad(offsetHours)}:${pad(offsetMin)}${sign===""?"Z":""}`;
}
something more global and not specific
a = new Date("11/04/2019 17:30:00");
a.setHours(a.getHours() + 2);
var d = a.toISOString().split(".")[0] + "+02:00"
Open in new window