user1658756
user1658756

Reputation: 1024

Get Current Time - Server or Client Side

Is there any server or client side way to determine their location and get the local time.

I'd like it to also update in real time, e.g. hour, mins, secs.

I'd prefer it if I can use PHP / JavaScript (jQuery included) or something like that.

Upvotes: 2

Views: 2104

Answers (3)

The Alpha
The Alpha

Reputation: 146219

You may want this

setInterval(function(){
    var dt=new Date(), h=dt.getHours(), m=dt.getMinutes(), s=dt.getSeconds(),
    curTime= pad(h)+':'+pad(m)+':'+pad(s); 
    document.getElementById('time').innerHTML=curTime;
}, 500);
function pad(n) { return ("0" + n).slice(-2); }

DEMO.

Upvotes: 2

Eman
Eman

Reputation: 6711

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

var now = new Date();

This will get the local client machine time.

Upvotes: 0

salih0vicX
salih0vicX

Reputation: 1373

You can try using jquery localtime plugin. Take a look [here]: http://code.google.com/p/jquery-localtime/wiki/Usage

Upvotes: 1

Related Questions