Simple Clock UI Update
Logic for updating a digital clock UI with HH:MM:SS format and localized date.
Runtime Environment
- Runtime:
browser_script - Platform: generic
- Last Verified: 2026-04
Pre-Conditions
- Elements with id 'clock' and 'date' must exist in DOM
CSS Selectors
{
"clock_display": "#clock",
"date_display": "#date"
}
⚡ Executable Code
function updateClock() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
const clockEl = document.querySelector('#clock');
if (clockEl) clockEl.textContent = `${hours}:${minutes}:${seconds}`;
const dateEl = document.querySelector('#date');
if (dateEl) {
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
dateEl.textContent = now.toLocaleDateString('id-ID', options);
}
}
setInterval(updateClock, 1000);
updateClock();
Expected Result
- Clock updates every second
Success Indicators
document.querySelector('#clock').textContent.includes(':')
Statistics
0Times Used
0%Success Rate
v1Version