HTML:
<div id="clock">
<div id="time"></div>
</div>
CSS:
#clock {
width: 350px;
background-color: rgba(0, 0, 0, 0.4);
margin: 0 15px 20px;
padding: 20px;
border-radius: 10px;
box-shadow: 0 10px 10px -5px rgba(0, 0, 0, 0.8);
border: 1px solid #333;
text-align: center;
}
#time {
color: #eee;
font-size: 2rem;
font-family: monospace;
}
JavaScript:
function dateTime() {
var element = document.getElementById('time');
var time = new Date();
var day = time.getDate().toString().padStart(2, '0');
var months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
var month = months[time.getMonth()];
var year = time.getFullYear();
var hour = time.getHours().toString().padStart(2, '0');
var minute = time.getMinutes().toString().padStart(2, '0');
var second = time.getSeconds().toString().padStart(2, '0');
element.textContent = `${day}/${month}/${year} ${hour}:${minute}:${second}`;
}
setInterval(dateTime, 1000);
dateTime();
Resultado: