(1)查看日期函数拓展
<?php
phpinfo();
打开上述页面之后,可以看到以下,证明已经安装日期拓展 浏览器输入php.net访问php的文档
(2)设置时区
方式一:修改配置文件php.ini
D:\ITSoft\wamp64\bin\php\php7.0.10\php.ini
[Date]
; Defines the default timezone used by the date functions
; http:
date .timezone = PRC
; http:
;date .default_latitude = 31.7667
; http:
;date .default_longitude = 35.2333
; http:
;date .sunrise_zenith = 90.583333
; http:
;date .sunset_zenith = 90.583333
方式二:date_default_timezone_set
<?php
echo '当前时区' .date_default_timezone_get();
var_dump(date_default_timezone_set('Asia/Shanghai' ));
echo '当前时区' .date_default_timezone_get();
方式三:init_set
设置指定配置选项的值。这个选项会在脚本运行时保持新的值,并在脚本结束时恢复
<?php
echo ini_get('date.timezone' );
ini_set('date.timezone' ,'Asia/Shanghai' );
echo ini_get('date.timezone' );
(3)常用时间函数
常用参数 date使用
<?php
ini_set('date.timezone' ,'Asia/Shanghai' );
echo date('Y年m月d日 H:i:s' );
echo date('H:i:s a' );
echo date('w' );
$runNian = date('L' );
if ($runNian ){
echo '是闰年' ;
}else {
echo '不是闰年' ;
}
<?php
echo time() ;
echo date('Y-m-d H:i:s' ,time() ) ;
echo date('Y-m-d H:i:s' ,time() +24 *60 *60 ) ;
echo mktime(0 ,0 ,0 ,2 ,1 ,2016 ) ;
<?php
echo date('Y-m-d H:i:s' ,time() ) ;
echo date('Y-m-d H:i:s' ,strtotime('+1 day' ) ) ;
echo date('Y-m-d H:i:s' ,strtotime('-5 days' ) ) ;
echo date('Y-m-d H:i:s' ,strtotime('+1 month' ) ) ;
echo date('Y-m-d H:i:s' ,strtotime('+5 months' ) ) ;
echo date('Y-m-d H:i:s' ,strtotime("last Monday" ) ) ;
echo strtotime("+1 week 2 days 4 hours 2 seconds" ) , "\n";
<?php
echo microtime();
echo microtime(true );
<?php
print_r(getdate() ) ;
<?php
var_dump(checkdate(1 ,32 ,2014 ) ) ;
(4)时间控件的使用
test.php
<!DOCTYPE html>
<html lang ="en" >
<head >
<meta charset ="UTF-8" >
<title > H5新增表单控件</title >
</head >
<body >
<h1 > H5新增表单日期时间控件</h1 >
<form action ='doAction.php' method ='post' >
<input type ="date" name ="datetime1" id ="time1" /> <br >
<input type ="submit" value ="提交" />
</form >
</body >
</html >
<?php
print_r($_POST );