时间:2021-07-01 10:21:17 帮助过:6人阅读
<?php
// returns false
echo checkdate(2,30,2005) ? "valid" : "invalid";
// returns true
echo checkdate(4,6,2010) ? "valid" : "invalid";
?>
getdate($ts)
在没有自变量的情况下,该函数以结合数组的方式返回当前日期与时间。数组中的每个元素代表日期/时间值中的一个特定组成部分。可向函数提交可选的时间标签自变量,以获得与时间标签对应的日期/时间值。
应用此函数来获得一系列离散的,容易分离的日期/时间值。
<?php // get date as associative array $arr = getdate(); echo "Date is " . $arr['mday'] . " " . $arr['weekday'] . " " . $arr['year']; echo "Time is " . $arr['hours'] . ":" . $arr['minutes']; ?> |
<?php // returns timestamp for 13:15:23 7-Jun-2006 echo mktime(13,15,23,6,7,2006); ?> |
<?php // format current date // returns "13-Sep-2005 01:16 PM" echo date("d-M-Y h:i A", mktime()); ?> |
<?php // 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")); ?> |
<?php // 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 "); ?> |
<?php // get starting value $start = microtime(); // run some code for ($x=0; $x<1000; $x++) { $null = $x * $x; } // get ending value $end = microtime(); // calculate time taken for code execution echo "Elapsed time: " . ($end - $start) ." sec"; ?> |
<?php // returns timestamp for 12:25:23 9-Jul-2006 echo gmmktime(12,25,23,7,9,2006); ?> |
<?php // format current date into GMT // returns "13-Sep-2005 08:32 AM" echo gmdate("d-M-Y h:i A", mktime()); ?> |
<?php // set timezone to UTC date_default_timezone_set('UTC'); ?> |