Материал из Web эксперт
Перейти к: навигация, поиск

Acquiring Date Information with getdate()

<title>Acquiring Date Information with getdate()</title>
$date_array = getdate(); 
foreach ( $date_array as $key => $val ) {
  print "$key = $val<br/>";
print "Today"s date: ";
print $date_array["mon"]."/".$date_array["mday"]."/".$date_array["year"];

Finding the month, day, and year

$a = getdate();
printf("%s %d, %d",$a["month"],$a["mday"],$a["year"]);

getdate() with a specific timestamp

$a = getdate(163727100);
printf("%s %d, %d",$a["month"],$a["mday"],$a["year"]);

Return array from getdate( )

Key             Value
seconds         Seconds
minutes         Minutes
hours           Hours
mday            Day of the month
wday            Day of the week, numeric (Sunday is 0, Saturday is 6)
mon             Month, numeric
year            Year, numeric (4 digits)
yday            Day of the year, numeric (e.g., 299)
weekday         Day of the week, textual, full (e.g., "Friday")
month           Month, textual, full (e.g., "January")
0               Seconds since epoch (what time( ) returns)

The Associative Array Returned by getdate()

Key         Description                                                  Example
seconds     Seconds past the minute (0�59)                               28
minutes     Minutes past the hour (0�59)                                 7
hours       Hours of the day (0�23)                                      12
mday        Day of the month (1�31)                                      20
wday        Day of the week (0�6)                                        4
mon         Month of the year (1�12)                                     1
year        Year (four digits)                                           2004
Yday        Day of year (0�365)                                          19
weekday     Day of the week (name)                                       Thursday
month       Month of the year (name)                                     January
0           Timestamp                                                    948370048

To obtain a number corresponding to the day of the week, use getdate() instead:

    $ts = strtotime("04 Jul 2007");
    $gd = getdate($ts); 
    $day = $gd["wday"];