NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - Date

Trieda

Koreň \ Bez triedy

Metóda - Date

The date() function is used for working with date and time. The function formats a local time and date according to a required format and returns as a formatted string.

The function takes two parameters: date (format [, timestamp = time() ] ).

  • The first one (format) is required, according to this parameter, the returned string is formatted.
  • The second one (timestamp) is optional, if we do not specify it, the actual time (=timestamp) is used (using the time() function). If we specify it, the function returns the formatted string according to the specified moment in time (timestamp) entered as the number of seconds till 1/1/1970.

Procedurálne

  • function Date () : void

Parametre

Žiadne

Mávratovej hodnoty

Vracia:

The string of the specific point in time (timestamp) formatted according to the first parameter of the function.

Príklady

If we pass only the first parameter, the current date and time is formatted and returned:

The format of the first parameter: "d", The returned value:

<?php
echo date("d");

The format of the first parameter: "h:i", The returned value:

<?php
echo date("h:i");

The format of the first parameter: "d:M:Y - H:i:s", The returned value:

<?php
echo date("d/M/Y - H:i:s");

If we also pass the second (optional) parameter, the returned value is formatted according to the specific time (timestamp):

The format of the first parameter: "d:M:Y - H:i:s", second parameter: time() + (246060), returned value::

<?php
echo date("d/M/Y - H:i:s", time()+(24*60*60));

The second parameter takes the current time (time()) and adds 246060 seconds, which is exactly 1 more day and this is also returned.

Súvisiace manuály

        Aktivity