There is no shortage of questions/answers on different variations of this, but I can't seem to find my scenario.
How (in NodeJS) do you convert strings like the following;
let timeZone = "America/Chicago";
let dateTimeStr = "01-26-2020 12:34:56 PM";
to a date time string with an offset like this?
2020-01-26T17:34:56-05:00
Here is what I'm trying
let timeZone = "America/Chicago";
let dateTimeString = "01-26-2020 12:34:56 PM";
newDate = new Date(dateTimeString);
console.log(`newDate=${newDate.toISOString()}`);
let dateTimeWithOffset = new Date(newDate).toLocaleString("en-US", {
timeZone: timeZone,
timeZoneName: "short",
});
console.log(`dateTimeWithOffset=${dateTimeWithOffset}`);
Which produces;
newDate=2020-01-26T17:34:56.000Z
dateTimeWithOffset=2020-01-26T17:34:56.000Z
I am looking to do this without any external lib.