Click here to Skip to main content
16,015,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
C#
<script type="text/javascript">
        var dt = jQuery.noConflict();
        dt(document).ready(function () {
            showTime();
            showdate();
        });

        function showdate()
        {
            var x = new Date();
            var x1 = (x.getMonth() + 1) + "/" + x.getDate() + "/" + x.getFullYear();
            document.getElementById('lblct').innerHTML = x1;
            window.setTimeout("showdate()", 1000);
        }

        function showTime()
        {
            var d = new Date();
            var hour = d.getHours() == 0 ? 12 : (d.getHours() > 12 ? d.getHours() - 12 : d.getHours());
            var min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
            var ampm = d.getHours() < 12 ? 'AM' : 'PM';
            var time = hour + ':' + min + ' ' + ampm;
            document.getElementById('lbldate').innerHTML = time;
            window.setTimeout("showTime()", 1000);
        }
  </script>



above javascript not showing exact time in different zone.How to modify the above java script to get the actual time in different zone or country

Thanks.
Posted
Updated 19-May-15 2:35am
v2
Comments
Kornfeld Eliyahu Peter 19-May-15 8:48am    
"The getHours() method returns the hour for the specified date, according to local time." (MDN and others)...
So your problem is not clear...
itsathere 19-May-15 9:34am    
it's clear and above javascript working but there is time difference at different country or zone.I have to show time with am/pm that's y i did it part wise(hour ,mins,ampm )
Andy Lanng 19-May-15 9:49am    
What's the difference you're seeing? is it out by 1 minutes or more?
PS: how are you testing it for different time-zones? Are you changing the system clock?
itsathere 20-May-15 1:55am    
it's 2 hours early in chicago..I have change it locally by changing different time zone it works fine but someone sitting at chicago is saying "it's 2 hours early".What to do now.
Andy Lanng 20-May-15 4:18am    
In javascript, new Date() will look at the systems local time and use that.
I can see two possibilities as to whats wrong, Neither are your code:
1: The individual in Chicago has the wrong time on his machine.
2: The individual in Chicago is using a remote desktop environment where the machine serving his desktop has a different time.

The only other option is that we have misinterpreted the intention of the code. We assume it is supposed to be showing them the local time?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900