I have a date I know is stored in Central Time. It has the following format: 2017-11-19T23:39:35.280000
. I want to turn this into an ISO-formatted date in the current timezone. I got it to work when simply creating a new Date()
-- but then when I subsequently call .toISOString()
, it goes haywire. Here's the code:
function convertCentralToLocal() {
const centralOffset = 360;
const dateInCentralMs = new Date('2017-11-19T23:39:35.280000').getTime();
const now = new Date();
const localOffset = now.getTimezoneOffset();
// this works: Sun Nov 19 2017 23:39:35 GMT-0600 (CST)
const d = new Date(dateInCentralMs + ((centralOffset - localOffset) * 60000));
// this seems to give the date six hours off: 2017-11-20T05:39:35.280Z
const iso = d.toISOString();
}
Is it an issue with GMT? I'm feeling lost.