2

before was getting time by timezone id using JavaScript this way.

    var tz = jstz.determine(); // Determines the time zone of the browser client
    var format = 'YYYY/MM/DD HH:mm:ss ZZ';
    alert(moment.tz('Europe/London').format(format));
    OR
    alert(moment.tz(tz.name()).format(format));

i was using two library one for getting timezone id from client browser and other one to get date & time based on timezone id. those two libraries are

<script type="text/javascript" src="Scripts/jstz.min.js"></script>
<script src="Scripts/moment.min.js" type="text/javascript"></script>
<script src="Scripts/moment-timezone-with-data-2010-2020.min.js" type="text/javascript">

but the problem is moment.js was giving time based on user pc date time setting. so if user pc date time is wrong then moment.js will return wrong date time. so i was looking for a way like how to get date & time by timezone id following ntp protocol.fortunately i got a solution from this url

their code as follows

// Get London time, and format it:
getTime('Europe/London', function(time){
    var formatted = time.getHours() + ':' 
                  + time.getMinutes() + ':'
                  + time.getSeconds();
    alert( 'The time in London is ' + formatted );
});

$.getTime = function(zone, success) {
    var url = 'http://json-time.appspot.com/time.json?tz='
            + zone + '&callback=?';
    $.getJSON(url, function(o){
        success && success(new Date(o.datetime), o);
    });
};

how far i understand the above code that it will call time.json and pass timezone id and response will back a new date and time based on timezone id.

i have one question that

1) please tell me someone that above js routine will return right date and time based on timezone id?

2) what about latency is there. suppose i made call to time.json and got the response back after 10 sec may be due to slow internet or any other reason. in this situation how could i get correct date & time.

so guide me what i need to do to always get correct time with date if response back after few sec or minute. also discuss what other best way out there to get NTP date & time using javascript. looking for guidance.

he main issue is latency...if i get response back after few sec or minute then how could i re-calculate time to make it accurate for latency or slow response problem.....please guide me someone. thanks

Mou
  • 15,673
  • 43
  • 156
  • 275
  • i also consult all these url https://www.npmjs.com/package/ntp-client http://stackoverflow.com/questions/5522191/javascript-ntp-time?rq=1 http://ejohn.org/blog/accuracy-of-javascript-time/ http://stackoverflow.com/questions/9818411/how-to-get-ntp-time-from-through-javascript – Mou Dec 19 '14 at 09:48
  • the main issue is latency...if i get response back after few sec or minute then how could i re-calculate time to make it accurate for latency or slow response problem.....please guide me someone. thanks – Mou Dec 19 '14 at 11:38

0 Answers0