当前位置:网站首页>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;
}
边栏推荐
- 190. Reverse Bits
- Acwing week 54
- Are you familiar with redis cache of highly paid programmers & interview questions series 114? How are redis keys designed? Are you familiar with the memory obsolescence mechanism?
- MySQL中的视图
- hw在即,你还不会看危险报文?
- Acwing week 52
- SQL Server 常用函数
- 241. Different Ways to Add Parentheses
- leetcode 85. Max rectangle
- openGauss内核分析之查询重写
猜你喜欢

HMS Core新闻行业解决方案:让技术加上人文的温度

BSN发展联盟理事长单志广:DDC可为中国元宇宙产业发展提供底层支撑

240. Search a 2D Matrix II

leetcode-二分法

“不敢去怀疑代码,又不得不怀疑代码”记一次网络请求超时分析

Istio服务网格中的流量复制

聊一聊数据库的行存与列存

程序员要不要选择软件人才外包公司?

Detailed installation tutorial of MySQL 8.0.29 under windows to solve the problem that vcruntime140 cannot be found_ 1.dll、plugin caching_ sha2_ password could not be loaded

"N'osez pas douter du Code, vous devez douter du Code" notez une analyse de délai de demande réseau
随机推荐
SQL and Oracle statements for eliminating duplicate records
Interpretation of the thesis -- factorization meets the neighborhood: a multifaceted collaborative filtering model
MySQL中触发器
论文专利博客写作总结
Linux setting enables Oracle10g to start automatically
【云原生】Nacos中的事件发布与订阅--观察者模式
461. Hamming Distance
Double hands of daily practice of Li Kou 2day9
散户开户哪个证券公司好?手机开户安全么?
融云:让银行轻松上“云”
程序员要不要选择软件人才外包公司?
Performance related indicators
测试组的任务职责和测试的基本概念
MySQL中的存储过程
Tasks and responsibilities of the test team and basic concepts of testing
338. Counting Bits
Acwing week 53
Interpretation of the paper -- scalable collaborative filtering with jointly derived neighborhood interpolation weights
155. Min Stack
769. Max Chunks To Make Sorted