2

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.

user1658756
  • 1,014
  • 5
  • 13
  • 27
  • have you tried googling for "javascript clock"? – jbabey Oct 18 '12 at 20:18
  • I believe this post would solve your question http://stackoverflow.com/questions/8090549/how-to-get-user-timezone-using-jquery – Douglas Cottrell Oct 18 '12 at 20:18
  • You probably want to use server time (in case client's time is incorrect) with PHP. – Ben Ashton Oct 18 '12 at 20:18
  • I think the `Date()` constructor in JavaScript provides the time from the user's PC, which should be set in his time zone. You could keep executing the `Date().getTime()` method every second with a timer and just have it update the innerText of some element on the page (or whatever you need to do with it.) – Micah Henning Oct 18 '12 at 20:19

3 Answers3

2

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.

The Alpha
  • 143,660
  • 29
  • 287
  • 307
1

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

salih0vicX
  • 1,363
  • 1
  • 8
  • 9
  • Yes, it does... All you need to do is to pass your UTC time (example: an event UTC 10:00) and viewer will have it translated to his/her current time based on location... – salih0vicX Oct 18 '12 at 20:53
0

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.

Eman
  • 6,383
  • 4
  • 23
  • 29