How to get global time (not PC time) using javascript or jquery?

I created a countdown timer using javascript; I can use jQuery. I want global time not PC time.

How can I get global time using javascript or jQuery?

+4
source share
3 answers

Use Time API: http://www.timeapi.org/

<script type="text/javascript"> function myCallback(json) { alert(new Date(json.dateString)); } </script> <script type="text/javascript" src="http://timeapi.org/utc/now.json?callback=myCallback"></script> 

You can use UTC methods from a Date object: http://www.w3schools.com/jsref/jsref_obj_date.asp

 var utcDate = new Date(json.dateString); alert(utcDate.getUTCFullYear() + '-' + utcDate.getUTCMonth() + utcDAte.getUTCDate()); 
+8
source

The Date object has built-in methods for getting UTC values. Instead of myDate.getHours() use myDate.getUTCHours() , etc.

See the MDN link for JavaScript date methods .

+1
source

Well, if you do not make a request to any service that is published as the current time of an atomic clock or something else, you will have to rely on your computers in local time. Because JS essentially relies on your local system.

0
source

Source: https://habr.com/ru/post/1403344/


All Articles