I am just get started in programming, and I have a question about time. The system I am working on is set in UTC time. However, I need to return a result in US Central time 'Chicago/Americas' in a specific format YYYY-MM-DD-hh:mm:ss. I've gone down the rabbit hole on the various methods of doing this, but none seems to have exactly what I am looking for and frankly I am more confused than when I started.
The closest I've been able to get to this is this, using toLocaleString in conjunction with toISOString.
var now = new Date(new Date().toLocaleString("en-US", {timeZone: "America/Chicago"})); // returns correct Timezone, but incorrect format
var StatusTime = now.toISOString(); //returns partially correct format.
The output from this is in the correct timezone, but the formatting is not quite right, e.g. '2022-07-15T12:01:57.000Z'. This response includes the Zulu time indicator, which is incorrect. There has got to be an easier way to accomplish this. Any advice would be appreciated. Thank you in advance.
JS dates are annoying, so consider using a library, like https://date-fns.org/