Get Date / Time of the HTML or Php System


How do I get autoaticante the system time without the user Interact?

echo"<td>Fecha de Entrega <input type=date name=fecha_entrega size=10 value=\""[email protected]$fecha_entrega."\"</td>";
asked by inusui 01.11.2018 в 07:58

2 answers


For that you need to set the time zone with date_default_timezone_set () , this way:

$date = date('m/d/Y h:i:s a', time());

Here is the list of time zones

answered by 01.11.2018 / 08:58

The point is that you want the time to be updated every second (I guess), showing it as a clock.

It would be best to do it on the client side, using the moment library, in Javascript.

To present the names of days / months in Spanish, you can include the library moment-with-locale.js

You put this at the beginning and it will show you the names in Spanish:


Let's see an example, using pure Javascript:

document.addEventListener("DOMContentLoaded", function(event) {
    var upDate = function() {
      var elFecha = document.querySelector("#fecha");
      var elHora = document.querySelector("#hora");
      var nowDate = moment(new Date());
      elHora.textContent = nowDate.format('HH:mm:ss');
      elFecha.textContent =
      nowDate.format('dddd DD [de] MMMM [de] YYYY ');
    setInterval(upDate, 1000);
#fecha {
  color: red;
<script src=""></script>

<div class="nowDateTime">
    <span id="fecha"></span><br />
    <span id="hora"></span>

The moment.js library has more interesting possibilities and you can discover them on their website .

answered by 01.11.2018 в 11:14