PHP/Date/getdate
Содержание
Acquiring Date Information with getdate()
<source lang="html4strict">
<html> <head> <title>Acquiring Date Information with getdate()</title> </head> <body>
<?php $date_array = getdate(); foreach ( $date_array as $key => $val ) {
print "$key = $val
";
} ?>
<? print "Today"s date: "; print $date_array["mon"]."/".$date_array["mday"]."/".$date_array["year"]; ?>
</body> </html>
</source>
Finding the month, day, and year
<source lang="html4strict">
<?php $a = getdate(); printf("%s %d, %d",$a["month"],$a["mday"],$a["year"]); ?>
</source>
getdate() with a specific timestamp
<source lang="html4strict">
<?php $a = getdate(163727100); printf("%s %d, %d",$a["month"],$a["mday"],$a["year"]); ?>
</source>
Return array from getdate( )
<source lang="html4strict">
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)
</source>
The Associative Array Returned by getdate()
<source lang="html4strict">
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
</source>
To obtain a number corresponding to the day of the week, use getdate() instead:
<source lang="html4strict">
<?php
$ts = strtotime("04 Jul 2007"); $gd = getdate($ts); $day = $gd["wday"];
?>
</source>