// returns false
echo checkdate(2,30,2005) ? "valid" : "invalid";
// returns true
echo checkdate(4,6,2010) ? "valid" : "invalid";
?>
getdate($ts)
在没有自变量的情况下,该函数以结合数组的方式返回当前日期与时间。数组中的每个元素代表日期/时间值中的一个特定组成部分。可向函数提交可选的时间标签自变量,以获得与时间标签对应的日期/时间值。
应用此函数来获得一系列离散的,容易分离的日期/时间值。
// get date as associative array $arr = getdate(); echo "Date is " . $arr['mday'] . " " . $arr['weekday'] . " " . $arr['year']; echo "Time is " . $arr['hours'] . ":" . $arr['minutes']; ?> |
// returns timestamp for 13:15:23 7-Jun-2006 echo mktime(13,15,23,6,7,2006); ?> |
// format current date // returns "13-Sep-2005 01:16 PM" echo date("d-M-Y h:i A", mktime()); ?> |
// returns 13-Sep-05 echo date("d-M-y", strtotime("today")); // returns 14-Sep-05 echo date("d-M-y", strtotime("tomorrow")); // returns 16-Sep-05 echo date("d-M-y", strtotime("today +3 days")); ?> |
// set locale to France (on Windows) setlocale(LC_TIME, "fra_fra"); // format month/day names // as per locale setting // returns "septembre" and "mardi" echo strftime("Month: %B "); echo strftime("Day: %A "); ?> |
// get starting value $start = microtime(); // run some code for ($x=0; $x$null = $x * $x; } // get ending value $end = microtime(); // calculate time taken for code execution echo "Elapsed time: " . ($end - $start) ." sec"; ?> |
// returns timestamp for 12:25:23 9-Jul-2006 echo gmmktime(12,25,23,7,9,2006); ?> |
// format current date into GMT // returns "13-Sep-2005 08:32 AM" echo gmdate("d-M-Y h:i A", mktime()); ?> |
// set timezone to UTC date_default_timezone_set('UTC'); ?> |