Javascript: Is That Possible To Get The Current Unix Timestamp When Machine's Time Is Incorrect?
Suppose that the time on my computer is incorrect (say 1 day ahead). Is there a way to get the current Unix Timestamp in this case? This answer outlines few way to get the Unix Tim
Solution 1:
Check for this api http://www.timeapi.org/
<scripttype="text/javascript">functionmyCallback(json) {
alert(newDate(json.dateString));
}
</script><scripttype="text/javascript"src="http://timeapi.org/utc/now.json?callback=myCallback"></script>
You can use the UTC methods from Date object: http://www.w3schools.com/jsref/jsref_obj_date.asp
var utcDate = newDate(json.dateString);
alert(utcDate.getUTCFullYear() + '-' + utcDate.getUTCMonth() + utcDAte.getUTCDate());
Solution 2:
I have a site specifically for such reasons: http://www.currentmillis.com/ You can make a request to the indicated PHP pages and you'll get back a UNIX timestamp, either in seconds or milliseconds.
Post a Comment for "Javascript: Is That Possible To Get The Current Unix Timestamp When Machine's Time Is Incorrect?"