That method .toLocaleTimeString()
takes arguments. The first is Locale (the code of the desired country, the second is an option object. There you can clear the option hour12
which may be true
or false
.
Different countries have different predetermined modes, port that you’ll have to test and define which ones you want. On MDN says so:
Whether to use 12-hour time (as opposed to 24-hour time). Possible values are true
and false
; the default is locale dependent.
I believe that pt-PT
and pt-BR
have the same foreknowledge, that is to say hour12: true
is 12 hours in format (with AM and PM).
Example:
<script>
function relogio(){
var d = new Date();
var t = d.toLocaleTimeString('pt-PT', {hour12: false});
document.getElementById('relogio').innerHTML = t;
}
setInterval(relogio, 1000);
</script>
In which browser? I made a test here and is printing in the format you want..
– Marllon Nasser
Both Chrome and Firefox, MAC OS system. On the system is right.
– denis