I am trying to implement a clock in php for my project, a clock that contains the date and time of my computer, until now I know something about how the function getdate () of php works and this is what I have:
<?php
$hoy = getdate(); //contiene todos los datos de fecha y hora
$dia = $hoy["wday"]; //obtengo número del día actual (0 a 6)
$dias = ["Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado"];
$dia = $dias[$dia]; //capturo el nombre del día
$ndia = $hoy["mday"]; //el número del día (1 a 31)
$mes = $hoy["mon"]; //el número del mes (1 a 12)
$meses = ["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre",];
$mes = $meses[$mes-1]; //capturo el nombre del mes
$año = $hoy["year"]; //el año (4 dígitos)
$hora = $hoy["hours"]; //la hora (esta necesito que sea la de mi pc)
$minuto = $hoy["minutes"]; //minutos (estos sí son los de mi pc)
$ceroh = ""; //cero extra por estética de la hora
if($hora < 10){
$ceroh = "0";
}else{
$ceroh = "";
}
$cerom = ""; //cero extra por estética de los minutos
if($minuto < 10){
$cerom = "0";
}else{
$cerom = "";
}
print_r("<a href='#' id='fechayhora'>"
.$dia." "
.$ndia." de "
.$mes." del "
.$año.", "
.$ceroh.$hora.":"
.$cerom.$minuto
." hrs</a>");
?>
The output is as follows: Wednesday November 2, 2016, 2:59 hrs
but the day and time are wrong because at this time is Tuesday November 1, 2016, 22:59 hrs on my pc and that is the time I want to show, you can see that is 4 hours ahead of time mine, that's why it also shows tomorrow.
Is there any way to take 4 hours of data that gets delivered to me ()?
EDIT
here says that the getdate () form is:
array getdate ([int $ timestamp = time ()])
And it returns an associative array that contains the information of the timestamp date, or the current local moment if timestamp is not given.
And I'm not passing that timestamp, so you should give me the local time, which is my pc or am I wrong?
EDIT 2
When I refer to getting the time of my pc, it is because in this case my pc is the server, the objective of the question is to modify the default time that the getdate () function brings, in this case, to remove it 4 hours . No reference is made to the time use of a city, although this is the formal way of working with dates and times on a server.