0

I make a clock that works very fine. I want to know how it works. For this clock I use the function time() from JavaScript. I want to make a clock that put the same hour even if you are not in the same time zone. Someone can tell me if with this function I can do it or how I have to do it?

The JavaScript code

function muestraReloj() {
var fechaHora = new Date();
var horas = fechaHora.getHours();
var minutos = fechaHora.getMinutes();
var segundos = fechaHora.getSeconds();

if(horas < 10) { horas = '0' + horas; }
if(minutos < 10) { minutos = '0' + minutos; }
if(segundos < 10) { segundos = '0' + segundos; }

document.getElementById("reloj").innerHTML = horas+':'+minutos+':'+segundos;
}

window.onload = function() {
setInterval(muestraReloj, 1000);
}

Thank You

2 Answers2

0

As far as PHP (and OS) is concerned, system time is the time. There is no other "independent" time the computer knows about. If you really do not trust the clock of your own system, you might want to fetch it across the network from some other machine. NTP synchronization daemon will do it for you on OS level, by the way.

Itz Raghu
  • 457
  • 2
  • 6
  • 16
  • The problem that I have is if I connect from europe I don't have the same hour that if I connect from asia for example. So i want to have the same hour for my web even if is not the real hour of the user's hour – Miguel Rubio Aug 15 '15 at 17:27
0

looks like u need to use the unixTimeStamp use it in your server with time()function from php then format it to Timezones that you want all world see

 $unixTime = time();
 // set default timezone
 date_default_timezone_set('Europe/Berlin');
 // output
 echo date('d M Y H:i:s Z',$unixTime);
 echo date('c',$unixTime);
vascowhite
  • 18,120
  • 9
  • 61
  • 77
irvinstone
  • 593
  • 4
  • 10