English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutorial di base di PHP

Tutorial avanzato di PHP

PHP & MySQL

Manuale di riferimento di PHP

Uso e esempio della funzione getdate() di PHP

Manuale delle funzioni di data/ora di PHP

La funzione getdate() di PHP ottiene informazioni sulla data/ora

Definizione e uso

La funzione getdate() di PHP viene utilizzata per ottenere informazioni sulla data/ora specificata. Accetta un parametro opzionale per specificare il timestamp per cui si desiderano informazioni. Se non viene passato alcun parametro, questa funzione restituisce informazioni sulla data/ora locale corrente.

Sintassi

getdate([$timestamp])

Parametro

Numero di serieParametri e descrizione
1timestamp

Opzionale) Questo rappresenta l'etichetta del timestamp della data/ora specificata.

Valore di ritorno

La funzione getdate() di PHP restituisce un array che contiene informazioni sulla data/ora specificata. Le unità di chiave dell'array associativo restituito includono:

Key units in the returned associative array
Key nameDescriptionReturn value example
"seconds"numeric representation of the second0 to 59
"minutes"numeric representation of the minute0 to 59
"hours"numeric representation of the hour0 to 23
"mday"numeric representation of the day of the month1 to 31
"wday"numeric representation of the day of the week0 (Sunday) to 6 (Saturday)
"mon"numeric representation of the month1 to 12
"year"4-digit number representing the full yearsuch as: 1999 or 2003
"yday"numeric representation of the day of the year0 to 365
"weekday"full text representation of the day of the weekSunday to Saturday
"month"full text representation of the month, such as January or MarchJanuary to December
0the number of seconds since the Unix epoch to the present day, and time() return value and for date() value is similar.System related, typical value is from -2147483648 to 2147483647.

PHP version

This function was initially introduced in PHP version 4 and can be used in all higher versions.

Online example

The following examples demonstrategetdate()Usage of the function-

<?php
   $info = getdate();
   print_r($info); 
?>
Test to see‹/›

Output result

Array
(
    [seconds] => 34
    [minutes] => 52
    [hours] => 12
    [mday] => 8
    [wday] => 5
    [mon] => 5
    [year] => 2020
    [yday] => 128
    [weekday] => Friday
    [month] => May
    [0] => 1588942354
)

Online example

Now, let's try to pass the timestamp to this function-

<?php
   $timestamp = time()-(23*12*30);
   $info = getdate($timestamp);
   print_r($info); 
?>
Test to see‹/›

Output result

Array
(
    [seconds] => 29
    [minutes] => 49
    [hours] => 10
    [mday] => 8
    [wday] => 5
    [mon] => 5
    [year] => 2020
    [yday] => 128
    [weekday] => Friday
    [month] => May
    [0] => 1588934969
)