Put all your code in a function and then call it every seconde with setInterval
function updateTime () {
let currentDateTime = new Date();
hours = ('0'+currentDateTime.getHours()).slice(-2);
mins = ('0'+currentDateTime.getMinutes()).slice(-2);
let formattedTime = hours + ":" + mins;
$('#time').html(formattedTime)
}
setInterval(updateTime, 1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="time"></div>
CLICK HERE to find out more related problems solutions.