How to get time zones or dates from the world's largest time sites using JavaScript?

I know we have an object in JavaScript (Date ();) that gives us the date. this object gives us the date of our pc. this is good, but you think our pc date is not set correctly and this object (Date ();) gives us the wrong date.

I want to know if we can get the date from major world time websites or time zones or time zone server to show the exact date even if our PC clock is not set correctly? for example get time or date from timeanddate.com or 24timezones.com or other clock servers ...

IF YES, HOW?
tnx for your attention ...

+3


source to share


1 answer


Use this in your HTML head.

<script type="text/javascript" src="http://www.timeapi.org/utc/now.json?callback=myCallback"></script>

      

then use this js code in <scripts>

function myCallback(json) {
    alert(new Date(json.dateString));
}

      



to get UTC time use this

function myCallback(json) {
    var utcDate = new Date(json.dateString);
    alert(utcDate.getUTCFullYear() + '/' + utcDate.getUTCMonth() + '/' + utcDAte.getUTCDate());
}

      

This will give you the correct time all the time

+3


source







All Articles