分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

php获取时间计算时间差

发布时间:2023-09-06 01:52责任编辑:沈小雨关键词:暂无标签

用php获取本周、本月第一天与最后天时间戳。

1,获取今天的时间范围:

<?php$start = mktime(0,0,0,date("m"),date("d"),date("Y")); $end = mktime(0,0,0,date("m"),date("d")+1,date("Y")); 

2,获取本周第一天/最后一天的时间戳

<?php$year = date("Y");$month = date("m");$day = date(‘w‘);$nowMonthDay = date("t");$firstday = date(‘d‘) - $day;if(substr($firstday,0,1) == "-"){ $firstMonth = $month - 1; $lastMonthDay = date("t",$firstMonth); $firstday = $lastMonthDay - substr($firstday,1); $time_1 = strtotime($year."-".$firstMonth."-".$firstday);}else{ $time_1 = strtotime($year."-".$month."-".$firstday);} ?$lastday = date(‘d‘) + (7 - $day);if($lastday > $nowMonthDay){ $lastday = $lastday - $nowMonthDay; $lastMonth = $month + 1; $time_2 = strtotime($year."-".$lastMonth."-".$lastday);}else{ $time_2 = strtotime($year."-".$month."-".$lastday);}

3,获取本月第一天/最后一天的时间戳

<?php$year = date("Y");$month = date("m");$allday = date("t");$strat_time = strtotime($year."-".$month."-1");$end_time = strtotime($year."-".$month."-".$allday);

计算时间差

$one = strtotime(‘2011-12-08 07:02:40‘);//开始时间 时间戳
$tow = strtotime(‘2011-12-25 00:00:00‘);//结束时间 时间戳
$cle = $tow - $one; //得出时间戳差值

$d = floor($cle/3600/24);
$h = floor(($cle%(3600*24))/3600);  //%取余
$m = floor(($cle%(3600*24))600/60);
$s = floor(($cle%(3600*24))`);

echo "两个时间相差 $d 天 $h 小时 $m 分 $s 秒"

php获取时间计算时间差

原文地址:https://www.cnblogs.com/yixing/p/8992215.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved