5

How to get server current date and time in JQuery?

My server time is in UK..

and we use in the system in India i get current date and time in JQuery it display India time.

But I want UK time in JQuery

SNS
  • 485
  • 6
  • 20

2 Answers2

5

The getTimezoneOffset() method returns the time difference between UTC time and local time, in minutes.

and also with the help of this question, your answer will be this

var d = new Date();
var n = d.getTimezoneOffset();
var ans = new Date(d.getTime() + n * 60 * 1000);
console.log(ans.getHours()+':'+ans.getMinutes()+':'+ans.getSeconds());

Reading this question and also this one also helps you.

Saeed
  • 5,413
  • 3
  • 26
  • 40
0

In JavaScript you can get the current date and time using the Date object

var now = new Date();

in php this code return server

<? echo '{serverTime: new Date(' . time()*1000 .')}';?>

or test this code

var myVar = setInterval(myTimer, 1000);

function myTimer() {
    var d = new Date();
    var t = d.toLocaleTimeString();
    document.getElementById("demo").innerHTML = t;
}
<!DOCTYPE html>
<html>
<body>

<p>A script on this page starts this clock:</p>
<p id="demo"></p>

</body>
</html>
Arman Bagheri
  • 608
  • 7
  • 19