Blog Index

World Times with JavaScript

Posted on 30th Nov 2017


Here is the JavaScript:

 


var timerID = null
var timerRunning = false

function stopclock(){
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function startclock(){
    stopclock()
    showtime()
}

function showtime(){
    var now = new Date()
    var hours = now.getHours()
    var minutes = now.getMinutes()
    var seconds = now.getSeconds()
    var timeValue = hours
    var timeValue1 = (hours - 6) % 24
    var timeValue2 = (hours - 9) % 24
    var timeValue3 = (hours + 6) % 24
    var timeValue4 = (hours + 4) % 24
    var timeValue5 = (hours + 3) % 24
    
    var minutesText = ((minutes < 10) ? ":0" : ":") + minutes
    var secondsText = ((seconds < 10) ? ":0" : ":") + seconds
    
    timeValue  += minutesText
    timeValue  += secondsText
    timeValue1  += minutesText
    timeValue1  += secondsText
    timeValue2  += minutesText
    timeValue2  += secondsText
    timeValue3  += minutesText
    timeValue3  += secondsText
    timeValue4  += (((minutes + 30) % 60 < 10) ? ":0" : ":") + (minutes + 30) % 60
    timeValue4  += secondsText
    timeValue5  += minutesText
    timeValue5  += secondsText

    document.getElementById("clockValue").innerHTML = timeValue 
    document.getElementById("clockValue1").innerHTML = timeValue1
    document.getElementById("clockValue2").innerHTML = timeValue2
    document.getElementById("clockValue3").innerHTML = timeValue3
    document.getElementById("clockValue4").innerHTML = timeValue4
    document.getElementById("clockValue5").innerHTML = timeValue5

    timerID = setTimeout("showtime()",1000)
    timerRunning = true
}

window.addEventListener("load", function() {startclock();})

Amsterdam:  
East Coast:  
Silicon Valley:  
Jakarta:  
Tibet:  
Dubai: