PHP100 2019-03-27
代码如下:
<? echo time(); ?>;
代码如下:
<? echo date ("Hhi l d F" ,time()); ?>;
代码如下:
<? echo strftime ("%Hh%M %A %d %b" ,time()); ?>;
代码如下:
<? $date_time_array = getdate (time()); echo $date_time_array[ "weekday"]; ?>;
代码如下:
<? echo mktime (0, 0,0 ,5, 27,2000 ); ?>;
代码如下:
<? $access_date = "2000/05/27"; //explode()函数用一个字符串作为分界来分解另一个字符串。这个例子$access_date通过字符串”/”来分解 $date_elements = explode("/" ,$access_date); // 此时 // $date_elements[0] = 2000 // $date_elements[1] = 5 // $date_elements[2] = 27 echo mktime (0, 0,0 ,$date_elements [1], $date_elements[ 2],$date_elements [0]); ?>;
代码如下:
<? // 来自Access的字符串 $date_time_string = "2000/05/27 02:40:21 PM"; // 将字符串分解成3部分-日期、时间和上午/下午 $dt_elements = explode(" " ,$date_time_string); // 分解日期 $date_elements = explode("/" ,$dt_elements[ 0]); // 分解时间 $time_elements = explode(":" ,$dt_elements[ 1]); // 如果是下午,我们将时间增加12小时以便得到24小时制的时间 if ($dt_elements [2]== "PM") { $time_elements[ 0]+=12;} // 输出结果 echo mktime ($time_elements [0], $time_elements[ 1], $time_elements[ 2], $date_elements[1], $date_elements[2], $date_elements[0]); ?>;
代码如下:
<? // 将目前的时间戳值放入一数组内 $timestamp = time(); echo $timestamp; echo "p"; $date_time_array = getdate( $timestamp); // 用mktime()函数重新产生Unix时间戳值 $timestamp = mktime($date_time_array ["hours"], $date_time_array["minutes" ],$date_time_array[ "seconds"],$date_time_array ["mon"], $date_time_array["mday" ],$date_time_array[ "year"]); echo $timestamp; ?>;
代码如下:
<? // 将目前的时间戳值放入一数组内 $timestamp = time(); echo $timestamp; echo "p"; $date_time_array = getdate( $timestamp); $hours = $date_time_array[ "hours"]; $minutes = $date_time_array["minutes"]; $seconds = $date_time_array[ "seconds"]; $month = $date_time_array["mon"]; $day = $date_time_array["mday"]; $year = $date_time_array["year"]; // 用mktime()函数重新产生Unix时间戳值 $timestamp = mktime($hours ,$minutes, $seconds,$month ,$day,$year); echo $timestamp; ?>;
代码如下:
<? // 将目前的时间戳值放入一数组内 $timestamp = time(); echo strftime( "%Hh%M %A %d %b",$timestamp); echo "p"; $date_time_array = getdate($timestamp); $hours = $date_time_array["hours"]; $minutes = $date_time_array["minutes"]; $seconds = $date_time_array["seconds"]; $month = $date_time_array["mon"]; $day = $date_time_array["mday"]; $year = $date_time_array["year"]; // 用mktime()函数重新产生Unix时间戳值 // 增加19小时 $timestamp = mktime($hours + 19, $minutes,$seconds ,$month, $day,$year); echo strftime( "%Hh%M %A %d %b",$timestamp); echo "br~E after adding 19 hours"; ?>;
代码如下:
<? function DateAdd ($interval, $number, $date) { $date_time_array = getdate($date); $hours = $date_time_array["hours"]; $minutes = $date_time_array["minutes"]; $seconds = $date_time_array["seconds"]; $month = $date_time_array["mon"]; $day = $date_time_array["mday"]; $year = $date_time_array["year"]; switch ($interval) { case "yyyy": $year +=$number; break; case "q": $month +=($number*3); break; case "m": $month +=$number; break; case "y": case "d": case "w": $day+=$number; break; case "ww": $day+=($number*7); break; case "h": $hours+=$number; break; case "n": $minutes+=$number; break; case "s": $seconds+=$number; break; } $timestamp = mktime($hours ,$minutes, $seconds,$month ,$day, $year); return $timestamp;} ?>;
代码如下:
<? include('dateadd.inc'); $temptime = time(); echo strftime( "%Hh%M %A %d %b",$temptime); $temptime = DateAdd("n" ,50,$temptime); echo "p"; echo strftime( "%Hh%M %A %d %b",$temptime); ?>;
代码如下:
<? Function DateDiff ($interval, $date1,$date2) { // 得到两日期之间间隔的秒数 $timedifference = $date2 - $date1; switch ($interval) { case "w": $retval = bcdiv($timedifference ,604800); break; case "d": $retval = bcdiv( $timedifference,86400); break; case "h": $retval = bcdiv ($timedifference,3600); break; case "n": $retval = bcdiv( $timedifference,60); break; case "s": $retval = $timedifference; break; } return $retval;} ?>;
代码如下:
<? include('datediff.inc'); include('dateadd.inc'); $currenttime = time(); echo "Current time: ". strftime("%Hh%M %A %d %b" ,$currenttime)."br"; $newtime = DateAdd ("n",50 ,$currenttime); echo "Time plus 50 minutes: ". strftime("%Hh%M %A %d %b" ,$newtime)."br"; $temptime = DateDiff ("n",$currenttime ,$newtime); echo "Interval between two times: ".$temptime; ?>;
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh