CH10,日期与时间,

来源:互联网 发布:淘宝开店项目 编辑:程序博客网 时间:2024/05/14 12:25
<?php error_reporting(E_ALL ^E_NOTICE);header('Content-type:text/html;charset=utf8');date_default_timezone_set("Etc/GMT-8");                     // 设置时区 当前为北京时区if($_POST['Submit']==true){    $month = trim($_POST[month]);    $day = trim($_POST[day]);    $year = trim($_POST[year]);    $dateH=date("H");    //var_dump(trim($_POST[month]));    $datei=date("i");    $dates=date("s");    $truedate=date("M-d-Y H:i:s", mktime($dateH,$datei,$dates,$month,$day,$year));}?> <style type="text/css">.STYLE1 {font-size: 13px;color: #0099CC;}.STYLE3 {font-size: 16px;font-weight: bold;color: #0099CC;}.STYLE5 {font-size: 16px; font-weight: bold; font-family: "华文仿宋"; color: #0099CC; }.STYLE7 {font-size: 13px}</style><title>获取指定任意一天的时间,p191,练习一</title><form id="form1" name="form1" method="post" action="#"><table width="446" border="5" cellpadding="5" cellspacing="5" bordercolor="#97C5F7">  <tr>    <td height="30" colspan="3" align="center">    <span class="STYLE3">获取指定任意一天的时间</span></td>  </tr>  <tr>    <td width="81" align="center"><span class="STYLE1">输入日期:</span></td>    <td width="226" height="24"><span class="STYLE1">      <input name="year" type="text" id="year" size="5" />      年      <input name="month" type="text" id="month" size="3" />      月      <input name="day" type="text" id="day" size="3" />      日</span></td>    <td width="73" align="center"><input name="Submit" type="submit" value="提交" /></td>    </tr>  <tr>    <td height="26" colspan="3" align="center"><span class="STYLE5">    正确的日期为:<?php echo $truedate;?></span></td>  </tr>  <tr>    <td height="73" colspan="3" align="center"><div align="left">    <span class="STYLE7">        注意:(1)在输入数字的时候,其中的年可以是两位或四位数字,        取值从0-69表示2000-2069年;70-99表示1970-1999年。        (2)在time_t是32位有符号整数的系统中,年的有效范围是1901到2038。        (3)目前所有的Windows系统都不支持负的时间戳。因此合法的年份范围只包括从1970到2038。    </span></div></td>  </tr></table></form><?phpecho "<br/>---------------输出下周时间----------------------<br/>";$nextWeek = time() + (7*24*60*60);echo 'Next Week:'.date('Y-m-d',$nextWeek);echo "<br/>------------------getdate-------------------<br/>";$arr = getdate();//获取当前时间信息var_dump($arr);echo $arr[year]."-".$arr[mon]."-".$arr[mday]." ";echo $arr[hours].":".$arr[minutes].":".$arr[seconds]." ".$arr[weekday];echo "<p>";echo "Today is the $arr[yday]th of year";echo "<br/>-----------------checkdate--------------------<br/>";var_dump(checkdate(2,29,2016));var_dump(checkdate(2,30,2016));//false;echo "<br/>-------------------------------------<br/>";echo date("l Y-m-d H:i:s T");//小写的L,来输出星期几;T表示时区;echo "输出转移字符:";echo date("\T\o\d\a\y \i\s \\t\h\e jS \o\f \y\e\a\\r");echo "<br/>------------strtotime把时间格式转化为时间戳-------------------------<br/>";$start_time = run_time(); $time1 = strtotime(date( "Y-m-d H:i:s")); $time2 = strtotime("2017-5-1 17:10:00"); $time3 = strtotime("2017-1-1"); $sub1 = ceil(($time2 - $time1) / 3600);            //60 * 60 $sub2 = ceil(($time3 - $time1) / (24*3600));           //60 * 60 * 24 echo "离放假还有<font color=red> $sub1 </font>小时!!!" ;   echo "<p>"; echo "离2013年元旦还有<font color=red>$sub2 </font>天!!!";echo "<br/>-----------microtime的返回值--------------------------<br/>";echo microtime();//0.99836400 1482218777echo "<br/>-------------------------------------<br/>";function run_time(){    list($msec,$sec) = explode(" ",microtime());//microtime()的括号不能丢;list赋值用;    return ((float)$msec + (float)$sec);}$end_time = run_time();echo "上面案例运行时间为:<font color=blue>".($end_time - $start_time)."</font>秒";echo "<br/>-------------------------------------<br/>";echo "<br/>--------------p191,练习二-----------------------<br/>";$dateY=date("Y");$datem=date("m");$dated=date("d");$dates1=mktime(17,10,0,$datem,$dated,$dateY);$dates2=mktime();$dates3=$dates1-$dates2;echo "距离下班时间还有".ceil($dates3/3600)."小时";echo "<br/>----------------p191,练习二--------------------<br/>";$date=mktime();//用gmmktime():函数也可以的;$str=mktime(0,0,0,8,8,2012);$str2=$str-$date;echo "距离奥运会开幕还有".ceil($str2/86400)."天";echo "<br/>-------------------------------------<br/>";echo "<br/>-------------------------------------<br/>";?>

0 0