On some computers the time is displayed with a 1 plus (as if daylight saving time is active), and on other PCs the time is normal.
On computers that show the wrong time on the site, on the PC itself the time is right, but on the site it shows 1 hour more.
How can I fix this problem?
In Brazil daylight saving time was extinguished from this year.
HTML:
<input name="ANOATUAL" type="hidden" id="ANOATUAL" value="<?php echo date("Y"); ?>">
<input name="TIMEATUAL" type="hidden" id="TIMEATUAL" value="<?php echo strtotime(date("Y-m-d H:i:s")); ?>">
<td id="relogio"></td>
JavaScript:
function iniciaCronometro(){
var timeAgora = parseFloat(document.getElementById("TIMEATUAL").value);
var anoAgora = document.getElementById("ANOATUAL").value;
var myDate = new Date(timeAgora * 1000);
var dataAtual = myDate.toLocaleString();
var t = dataAtual.split(anoAgora);
var horaAtual = trim(t[1]);
var tempo = horaAtual.split(":");
var h = tempo[0];
var i = tempo[1];
var s = tempo[2];
document.getElementById("relogio").innerHTML = h+':'+i;
document.getElementById("TIMEATUAL").value = (timeAgora + 1);
setTimeout("iniciaCronometro()",1000);
}
Trim function:
function trim(str){
return str.replace(/^\s+|\s+$/g,"");
}
As this brilliant book suggests "Best practice: avoid the built-in Date"!
As we have discussed in chat, the following works for you.
HTML:
Javascript: