Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Javascript adding Timezone in my current script

i have this code on my script to show ticking clock

<script type="text/javascript">
    function showTime() {
        var date = new Date(),
            time = new Date(Date.UTC(
                date.getFullYear(),
                date.getMonth(),
                date.getDate(),
                date.getHours(),
                date.getMinutes(),
                date.getSeconds()
            ));

        document.getElementById('time').innerHTML = time.toLocaleTimeString();
    }

    setInterval(showTime, 1000);

</script>

Anyone know how to change the timezone to a specific timezone like "Asia/Jakarta"
Thanks before!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

for info : — list of TZ

const timeDisplay = document.getElementById('time');


timeDisplay.textContent = new Date().toLocaleTimeString('ID','Asia/Jakarta')
 
<p id="time"></p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading