troubleshooting Question

How to get the locatime using javascript

Avatar of srk1982
srk1982 asked on
JScript
4 Comments1 Solution334 ViewsLast Modified:
Hi experts,

    I am using this js function for getting the local time according to country where the website is viewed.
   If the website is viewed in singapore it shud show the singapore local time.
   If the website is viewed in hongkong it shud show the Hongkong local time.

It is not working for me... OR is there any other way??

URGENT...Thanks.
// JScript File
var WindowObjectReference = null;
//Region Time Display Function
/*Time Display Function for all Website pages*/
    var worldtime = new Array()
    
    worldtime[0]="Hong Kong,8"
 
    var hours
    var shifthours
    var minutes
    var seconds
    var localhours
    function showTime()
    {
        for (i=0; i<=worldtime.length-1;i++) 
        {
		    thisplace=worldtime[i].split(",")
		    thistime= new Date()
		    hours=thistime.getUTCHours()
		    hours=eval(hours)
		    shifthours=eval(thisplace[1])
		    localhours=eval(shifthours+hours)
		    if (localhours <0) {localhours=24+localhours}
		    if (localhours >=24) {localhours=localhours-24}
    	     
		    minutes=thistime.getUTCMinutes()
		    seconds=thistime.getUTCSeconds()
    	
		    if (thisplace[0]=='Delhi') 
		    {
			    minutes=eval(minutes+30)
			    if (minutes>=60) {
				    minutes=eval(minutes-60)
				    localhours=eval(localhours+1)
			        }
		    }
		    if (eval(minutes) < 10) {minutes="0"+minutes}
		    if (eval(seconds) < 10) {seconds="0"+seconds}
		    if (eval(localhours) < 10) {localhours="0"+localhours}
    		    
 
		       
		        if(document.getElementById('hdate')!=null && thisplace[0]=='Hong Kong')
		            document.getElementById('hdate').innerText = thistime.toLocaleDateString()+ ' ' + localhours+":"+minutes;
        }
        
            setTimeout("showTime()",1000)
    }
    
    showTime();
//End Region Time Display Function
</script>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros