Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
124
rated 0 times [  125] [ 1]  / answers: 1 / hits: 15157  / 12 Years ago, sun, march 25, 2012, 12:00:00

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



How could I get the global time using javascript or the jQuery?


More From » jquery

 Answers
32

Use a time API like: 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 the UTC methods from Date object: http://www.w3schools.com/jsref/jsref_obj_date.asp



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

[#86613] Friday, March 23, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
robinh

Total Points: 371
Total Questions: 105
Total Answers: 89

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
;