当前位置:网站首页>php两个时间戳相隔多少天
php两个时间戳相隔多少天
2022-06-22 12:42:00 【大得369】
根据需求不同 算出相隔时间天数也不同
需求一 2020-4-26 23:59:59 距离2020-4-27 0:00:00 时间相隔1天
因为26到27号 不管是差几秒 都是间隔1天
$day1= 1587916799;//2020-4-26 23:59:59
$day2= 1587916800;//2020-4-27 0:00:00
//date_diff两个参数 day1 day2互换位置也可以 不影响结果
$cha = date_diff(date_create(date('Ymd',$day1)),date_create(date('Ymd',$day2)));
$day = $cha->days;
var_dump($day);//1
需求二 2020-4-26 23:59:59 距离2020-4-27 0:00:00 时间相隔0天
两个时间相减 等到了整天 算一天
$day1= 1587916799;//2020-4-26 23:59:59
$day2= 1587916800;//2020-4-27 0:00:00
$timediff = $day2 - $day1;
$days = intval($timediff / 86400);
var_dump($days);//0/**
* 获取两个时间戳相差月数
* @param int $time1
* @param int $time2
* @return number
*/
function get_diff_months($time1,$time2){
$months=0;
$t=0;
if($time1>$time2){
$t=$time1;
$time1=$time2;
$time2=$t;
}
$y1=date('Y',$time1);
$y2=date('Y',$time2);
$m1=date('m',$time1);
$m2=date('m',$time2);
$months=($y2-$y1)*12+($m2-$m1);
return $months;
}
边栏推荐
- What you must understand before you are 30
- leetcode 32. Longest valid bracket
- 【云原生】Nacos中的事件发布与订阅--观察者模式
- [cloud native] event publishing and subscription in Nacos -- observer mode
- MySQL中的存储过程
- 318. Maximum Product of Word Lengths
- leetcode 99. Restore binary search tree
- 高薪程序员&面试题精讲系列114之Redis缓存你熟悉吗?Redis的key如何设计?内存淘汰机制你熟悉吗?
- "N'osez pas douter du Code, vous devez douter du Code" notez une analyse de délai de demande réseau
- 谈谈人生风控
猜你喜欢
随机推荐
leetcode 11. Container with the most water
简简单单的科研秘籍
Record the solution of failing to log in after the alicloud ECS instance is restarted (hands-on practice)
Rigid demand of robot direction → personal thinking ←
In June, China database industry analysis report was released! Smart wind, train storage and regeneration
Common writing methods and excellent examples of acknowledgments in graduation thesis writing
Run sqoop1.4.5 to report warning: does not exist! HCatalog jobs will fail.
leetcode-区间dp
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
Problème de sous - séquence / substrat leetcode
Leetcode interval DP
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
Oracle cursor
Eureka的InstanceInfoReplicator类(服务注册辅助类)
Oracle stored procedure 2
高薪程序员&面试题精讲系列114之Redis缓存你熟悉吗?Redis的key如何设计?内存淘汰机制你熟悉吗?
Redis password modification, startup, view and other operations
leetcode 829. Sum of continuous integers
769. Max Chunks To Make Sorted
476. Number Complement








