JSFiddle - React, Tailwind, and code Playground
by Nic Fontaine
JavaScript
function timeConversion(s) {
let [h, m, sec] = s.split(":");
const str = sec.slice(2);
sec = sec.slice(0,2);
if (str === "PM" && Number(h) < 12) {
h = Number(h) + 12;
} else if (str === "AM" && Number(h) === 12) {
h = "00";
}
return (`${h}:${m}:${sec}`);
}
console.log(timeConversion("07:05:45PM"));
async function getter (URL) {
const response = await fetch(URL, {
method: "GET"
});
if (!response.ok) {
throw new Error("Network Error");
}
}
async function parent () {
try {
const res = getter("example.com");
console.log(res);
} catch (err) {
console.error(err);
}
}