Con php
Código PHP:
Ver original<?php header("Content-Type: text/html;charset=utf-8"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sincronizar tiempo timeServer + Php</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css">
/*<![CDATA[*/
body{
font-family: verdana, sans-serif;
font-size: 12pt;
color:#241A17;
}
/*]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
function HoraAMPM() {
var fecha = new Date();
var horas = fecha.getHours();
var minutos = fecha.getMinutes();
var ampm = horas >= 12 ? 'pm' : 'am';
horas = horas % 12;
horas = horas ? horas : 12;
minutos = minutos < 10 ? '0'+minutos : minutos;
var tiempo = horas + ':' + minutos + ' ' + ampm;
document.write(tiempo);
}
function Hora24() {
var fecha = new Date();
var horas = fecha.getHours();
var minutos = fecha.getMinutes();
minutos = minutos < 10 ? '0'+minutos : minutos;
var tiempo = horas + ':' + minutos ;
document.write(tiempo);
}
//]]>
</script>
</head>
<body>
<?php
function obtener_tiempo_tmeserver ($timeserver, $socket) {
$fp = fsockopen($timeserver,$socket,$err,$errstr,5); if ($fp) {
$valor_tiempo = fread($fp,49); }else{
$valor_tiempo = " ";
}
$ret[] = $valor_tiempo;
$ret[] = $err; # error code
$ret[] = $errstr; # error text
return($ret);
} # function obtener_tiempo_tmeserver
$timeserver = "time.nist.gov"; // indicar el timeserver aqui
$timercvd = obtener_tiempo_tmeserver($timeserver,37);
if (!$timercvd[1]) {
$valor_tiempo = bin2hex ($timercvd[0]); $tmestamp = $valor_tiempo - 2208988800;
$datum = date("Y-m-d (D) H:i:s",$tmestamp - date("Z",$tmestamp)); $doy = (date("z",$tmestamp)+1);
echo "Tiempo chequeado en el servidor <b>",$timeserver,"</b> : [<span style=\"color: red\">",$valor_tiempo,"</span>]";
echo " (segundos desde 1900-01-01 00:00.00).<br />\n";
echo "La fecha y hora actual es ",$datum," UTC.<br /> ";
echo "El valor unix de time es $tmestamp.<br />\n";
}else{
echo "Error al intentar acceder al timeServer <b>$timeserver</b><p style=\"width: 500px;\">";
echo "Código de error: <b>" . $timercvd[1] . "</b><br /> " . htmlentities($timercvd[2]) . "<br /></p>\n"; }
?>
<div>
<br />
<p>Hora local con javascript</p>
<script type="text/javascript">
//<![CDATA[
HoraAMPM();
//]]>
</script>
<br />
<script type="text/javascript">
//<![CDATA[
Hora24();
//]]>
</script>
</div>
</body>
</html>
solo tenés que definir el TimeServer en la linea
$timeserver = "time.nist.gov"; // indicar el timeserver aqui
Saludos