JSFiddle - React, Tailwind, and code Playground
by 1eddy87
HTML
<span id="local"></span>
CSS
body {
padding: 20px;
}
JavaScript
var output = document.querySelector("#local");
var isoDate = new Date().toISOString();
var res = isoDate.split("T").pop();
function updateTime(theTime) {
var date = new Date()
var timeParts = theTime.split(':')
date.setUTCHours(~~timeParts[0])
date.setUTCMinutes(~~timeParts[1])
date.setUTCSeconds(~~timeParts[2])
var formattedTime = date.getHours() + ':' + ('0' + date.getMinutes()).slice(-2)
output.textContent = 'Time in your local time: ' + formattedTime
}
updateTime(res);