网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

PHP的日期和时间

一、UNIX时间戳

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、微信小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了湟源免费建站欢迎大家使用!

   以32位的整数表示格林威治标准时间。UNIX时间戳是从1970年1月1日零点开始起到当前时间所经历的秒数。

1、将日期和时间转变成UNIX时间戳

(1)mktime()函数

echo date("Y-m-d-h-m-s",mktime(12,10,56,12,67,2016))."\n";

?>

(2)strtotime()函数

echo date("Y-m-d",strtotime("now"))."
";

echo date("Y-m-d",strtotime("10 may 2014"))."
";

echo date("Y-m-d",strtotime("+2 day"))."
";

echo date("Y-m-d",strtotime("last monday"));

?>
(3)实例:用strtotime()函数编写一个纪念日的倒计时程序

$now=strtotime("now");

$endtime=strtotime("2018-6-19 23:59:59");

$second=$endtime-$now;

$year=floor($second/60/60/24/365);

$temp=$second-$year*365*24*60*60;

$month=floor($temp/60/60/24/30);

$temp=$temp-$month*30*24*60*60;

$day=floor($temp/60/60/24);

$temp=$temp-$day*24*60*60;

$hour=floor($temp/60/60);

$temp=$temp-$hour*60*60;

$minute=floor($temp/60);

$second1=$temp-$minute*60;

echo "距离大学毕业还有".$year."年".$month."月".$day."日".$hour."小时".$minute."分".$second1."秒";


2、日期的计算


//在PHP脚本中接收HTML表单用户提交的出生日期,计算这个用户的年龄

$year=1992;

$month=11;

$day=2;

$birthday=mktime(0,0,0,$month,$day,$year);       //将出生日期转变为UNIX时间戳

$nowdate=time();

$ageunix=$nowdate-$birthday;

$age=floor($ageunix/60/60/24/365);

echo "您的年龄是".$age."岁";

?>

二、在PHP中获取日期和时间

三、修改PHP默认时区

四、使用微秒计算PHP脚本执行时间

//使用微秒计算PHP脚本执行时间

class Timer{

private $startTime=0;

private $stopTime=0;

function start(){

$this->startTime=microtime(true);

}

function stop(){

$this->stopTime=microtime(true);

}

function spent(){

return round(($this->stopTime-$this->startTime),4);

}

}

$Timer=new Timer();

$Timer->start();

usleep(2000);

$Timer->stop();

echo "执行该脚本用时".$Timer->spent()."秒";

?>

五、日历类


分享文章:PHP的日期和时间
文章路径:http://bjjierui.cn/article/gpjose.html

其他资讯