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?
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
Date
var utcDate = new Date(json.dateString); alert(utcDate.getUTCFullYear() + '-' + utcDate.getUTCMonth() + utcDAte.getUTCDate());
The Date object has built-in methods for getting UTC values. Instead of myDate.getHours() use myDate.getUTCHours() , etc.
myDate.getHours()
myDate.getUTCHours()
See the MDN link for JavaScript date methods .
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.
Source: https://habr.com/ru/post/1403344/More articles:Testing the App on the App Store - Newbie - objective-cAndroidProblems compiling any java code in Eclipse - javaHow to create a new database for a new user in CouchDB without the Tier application - couchdbPre-populated baseline data using only the first application launch - iosGo to a specific point in the binary in C (using fseek) and then read from that point (using fread) - cHow to remove duplicated SNPs using PLink? - bioinformaticsPseudorandom number generator s> 64-bit seed for dragging a deck of 52 cards - randomjQuery revive percentage? - jqueryOffline support for AFNetworking request queues and save to disk? - iosAll Articles