当前位置:网站首页>PHP gets the number of days, hours, minutes and seconds between the two timestamps
PHP gets the number of days, hours, minutes and seconds between the two timestamps
2022-07-02 17:53:00 【Famine~】
public function time_cha()
{
$s_date ="2015-12-12 16:00:00";
$e_date ="2016-12-13 18:00:00";
$cha = strtotime($e_date)-strtotime($s_date);
// year
$year = floor((strtotime($e_date)-strtotime($s_date)) / (31536000));
echo "1、 The difference is years :".$year." year <br/><br/>";
// month
$month = floor(($cha - $year * 31536000) / (2592000));
$month_total = floor($cha / 2592000);
echo "2、 Months difference :".$month." month <br/><br/>";// Except last year
echo "3、 Months difference :".$month_total." month <br/><br/>";// Total months
// Japan
$day_total = floor((strtotime($e_date)-strtotime($s_date))/86400);
echo "4、 The total difference is :".$day_total." God <br/><br/>";
// when
$hour = floor((strtotime($e_date)-strtotime($s_date))%86400/3600);
$hour_total = floor((strtotime($e_date)-strtotime($s_date)));// Total phase difference N Hours
echo "5、 Hours difference :".$hour." Hours <br/><br/>";
echo "6、 Total hours difference :".$hour_total." Hours <br/><br/>";
// branch
$minute = floor((strtotime($e_date)-strtotime($s_date))%86400/60);
$minute_total = floor((strtotime($e_date)-strtotime($s_date))/60);
echo "7、 Minutes difference :".$minute." minute <br/><br/>";
echo "8、 Total minutes difference :".$minute_total." minute <br/><br/>";
// second
$second = floor((strtotime($e_date)-strtotime($s_date))%86400%60);
$second_total = floor((strtotime($e_date)-strtotime($s_date)));
echo "9、 Seconds difference :".$second." second <br/><br/>";
echo "10、 Total seconds difference :".$second_total." second <br/><br/>";
}
边栏推荐
- HDU - 1114 Piggy-Bank(完全背包)
- php获取两个时间戳之间相隔多少天多少小时多少分多少秒
- 把xshell連接服務器關掉,運行的jar包就自動停止的解决方案
- Does pytorch support 32 bits?
- What are the green field and brown field models in software development - green field development and brown field development
- Five reasons to choose SAP Spartacus as the implementation framework of SAP commerce cloud storefront
- How to create a new page for SAP Spartacus storefront
- The bottom simulation implementation of vector
- [target tracking] |siamfc
- chrome瀏覽器快速訪問stackoverflow
猜你喜欢
Larvel document reading notes custom authentication login and registration using larvel 8
My creation anniversary
Experience Alibaba cloud character recognition OCR
Modbus协议通信异常
【Zuul】com. netflix. zuul. exception. ZuulException: Hystrix Readed time out
Troubleshooting ideas that can solve 80% of faults
蓝牙技术|物联网的可穿戴设备新工作模式,蓝牙BLE助力新工作模式
开发一个禁止删除namespace的控制器
EdgeNeXt打出了一套混合拳:集CNN与Transformer于一体的轻量级架构
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
随机推荐
finally详解
Longest non repeating subarray
智能水电表能耗监测云平台
MB10M-ASEMI整流桥MB10M
Keras深度学习实战——基于VGG19模型实现性别分类
SAP commerce Cloud Architecture Overview
Bluetooth technology | new working mode of wearable devices of the Internet of things, and Bluetooth ble helps the new working mode
List summation [dummy+ tail interpolation + function processing list reference common pit]
Solution to the problem that the easycvr kernel of intelligent video analysis platform cannot be started as a service
PMS150C应广单片机开发案例
Modbus protocol communication exception
POJ - 1458 common subsequence (longest common subsequence)
Redisson 高性能 Redis 分布式锁源码分析
把xshell连接服务器关掉,运行的jar包就自动停止的解决方案
What are the green field and brown field models in software development - green field development and brown field development
aloam 代码阅读与总结
Common SQL statements (complete example)
Yingguang pmc131 SOP16 16pin eight bit MCU
win10 kms activator
应广单片机PMS150/PMC150/PMS150C消费类单片机