I wrote a very basic JS function to create a clock. It uses a very basic replace method to change a "," to a "|" symbol. The desired output is "Thursday, Jan. 12, 2023 | 10:00:00 p.m."
const refreshTime = () => {
let t = 0;
const timeNow = (new Date).toLocaleString('en-CA', {
timeZone: "America/Edmonton", year: "numeric", month: "short",
weekday: "long", day: "numeric", hour12:true, hour: "numeric",
minute: "2-digit", second: "2-digit"
}).replace(/,/g, match => ++t === 3 ? ' |' : match)
const time = document.querySelector(".time")
time.innerHTML = `${timeNow}`
}
refreshTime()
setInterval(refreshTime, 1000)
<h2 class="time">""<h2>
As you can see here on the deployed site, this clock works fine in the header section. But once you click on that same link on a phone, it displays as "Thursday, Jan 12, 2023 at 10:00:00 p.m."
I've tried with multiple mobile browsers and also tried deploying on vercel and it is giving me the same result. How can I make sure this displays as intended on mobile?