JavaScript Algorithm: Time Conversion

added by JavaScript Kicks
12/5/2019 9:46:16 AM

416 Views

In 24-hour format, 12:00 PM is ... 12:00 but for 12:00 AM, it is 0:00 so we write the following statements: // if midnight// if afternoonif (hour === 12 && s.indexOf("AM") !== -1) {if (hour === 12 && s.indexOf("PM") !== -1) { return (time + timeFormat);} return ("00" + timeFormat);} If the hour variable equals to 12, we must also look back to our original string and see if it contains PM or AM using indexOf.


0 comments