SNS
SNS

Reputation: 483

How to get server current date and time in JQuery

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

Upvotes: 5

Views: 10117

Answers (2)

Saeed
Saeed

Reputation: 5488

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.

Upvotes: 5

Arman Bagheri
Arman Bagheri

Reputation: 630

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>

Upvotes: 0

Related Questions