gs650x
gs650x

Reputation: 405

Extracting time form JS Date Object

I have below JS code

let options = { hour12: false,  timeZone: 'America/Chicago', timeStyle: 'short' };

let myDate = new Date('2021-06-07T05:46:00.000Z').toLocaleTimeString("en-US", options);

The expected output from above is 00:46 as I am using hour12 to false but instead it returns 24:46 which is an invalid time, could someone please highlight what am I missing?

Upvotes: 0

Views: 27

Answers (1)

DecPK
DecPK

Reputation: 25408

use en-GB instead of en-US

let options = {
  hour12: false,
  timeZone: "America/Chicago",
  timeStyle: "short",
};

let myDate = new Date("2021-06-07T05:46:00.000Z").toLocaleTimeString(
  "en-GB",
  options
);

console.log(myDate);

Upvotes: 2

Related Questions