Turns out I have the following watch, in javascript.
function ActivaReloj(){
var now = new Date();
var hora = now.getHours();
var minuto = now.getMinutes();
var segundo = now.getSeconds();
segundo = CheckZeros(segundo);
minuto = CheckZeros(minuto);
hora = CheckZeros(hora);
if (hora >= 12){
Imprime = hora + " "+":"+" "+minuto+" "+":"+" "+segundo+" "+"PM";
}else if (hora <= 12){
Imprime = hora + " "+":"+" "+minuto+" "+":"+" "+segundo+" "+"AM";
}
document.form_reloj.reloj.value = Imprime;
setTimeout("ActivaReloj()",500);
}
function CheckZeros(i){
if (i < 10) {
i = "0" + i;
}
return i;
}
input{
width: 6cm; border-style: none; background-color: rgba(0,0,0,0.6); color: white; border-radius: 10px; text-align: center; height: 1cm; font-size: 14pt; font-family: 'Roboto', 'Segoe UI'; font-weight: 300;}
body{
background-color: #00A623;
}
form{
margin-top: 5mm;
margin-bottom: -10cm !important;
}
<body onload="ActivaReloj()">
<form name="form_reloj" id="clock">
<input type="text" name="reloj" disabled="disabled">
</form>
</body>
But as this value is easily modifiable, modifying the time of the equipment ; what I am trying now is that the clock obtains the time from the server , which, even if the time of the computer changes, the clock should not change.
I tried in the following way.
$now = Carbon\Carbon::now()->toTimeString();
return view('MyView', ['now'=>$now]);
And then in it <input>
I added the variable:
<input type="text" disabled="disabled" value="{{$now}}">
But, the time is not updated automatically.
Make sure to put an id to your input
Since from
Laravel
gets the date with the formatH:M:S
, we can get these values to create an object of the Date() class , since the day, month and year do not matter, we can send zero in those parameters to the constructor.We will make use of its function to add zeros to the left, for the hours, minutes and seconds, and finally we use a ternary operator to assign
AM
orPM
as the case may be.HTML (blades)
JS