当前位置:网站首页>php获取两个时间戳之间相隔多少天多少小时多少分多少秒
php获取两个时间戳之间相隔多少天多少小时多少分多少秒
2022-07-02 15:56:00 【荒~】
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 = floor((strtotime($e_date)-strtotime($s_date)) / (31536000));
echo "1、相差年数:".$year." 年<br/><br/>";
//月
$month = floor(($cha - $year * 31536000) / (2592000));
$month_total = floor($cha / 2592000);
echo "2、相差月数:".$month." 月<br/><br/>";//除去年
echo "3、相差月数:".$month_total." 月<br/><br/>";//总月数
//日
$day_total = floor((strtotime($e_date)-strtotime($s_date))/86400);
echo "4、相差总天数:".$day_total." 天<br/><br/>";
//时
$hour = floor((strtotime($e_date)-strtotime($s_date))%86400/3600);
$hour_total = floor((strtotime($e_date)-strtotime($s_date)));//总相差N小时
echo "5、相差小时数:".$hour." 小时<br/><br/>";
echo "6、相差总小时数:".$hour_total." 小时<br/><br/>";
//分
$minute = floor((strtotime($e_date)-strtotime($s_date))%86400/60);
$minute_total = floor((strtotime($e_date)-strtotime($s_date))/60);
echo "7、相差分钟数:".$minute."分钟<br/><br/>";
echo "8、相差总分钟数:".$minute_total."分钟<br/><br/>";
//秒
$second = floor((strtotime($e_date)-strtotime($s_date))%86400%60);
$second_total = floor((strtotime($e_date)-strtotime($s_date)));
echo "9、相差秒数:".$second." 秒<br/><br/>";
echo "10、相差总秒数:".$second_total." 秒<br/><br/>";
}
边栏推荐
- ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
- Platform management background and business menu resource management: business permissions and menu resource management design
- wps插入图片后使图片完整显示
- Common SQL statements (complete example)
- 应广单片机003烧录器自定义封装使用技巧
- 原厂原装 应广单片机PMS134方案开发应用案例
- 【GAMES101】作业4 Bézier 曲线
- Example nonlinear integer programming
- HDU - 1114 Piggy-Bank(完全背包)
- RK1126平台项目总结
猜你喜欢
随机推荐
vector的底层模拟实现
Huimang micro IO MCU ft60f011a-rb
easyAI笔记——机器学习
Alibaba Tianchi SQL learning notes - Day3
easyAI笔记——深度学习
PMS132B单片机TWS数码管蓝牙充电仓方案开发
ROS knowledge points -- the difference between ros:: nodehandle N and NH ("~")
No such file or directory: ‘/tmp/tmpxxx/tmpxxx.py‘
finally详解
HDU - 1114 Piggy Bank (full backpack)
常用SQL语句(完整范例)
将您的基于 Accelerator 的 SAP Commerce Cloud Storefront 迁移到 Spartacus
【历史上的今天】7 月 2 日:BitTorrent 问世;商业系统 Linspire 被收购;索尼部署 PlayStation Now
Helm kubernetes package management tool
应广单片机开发案例
【GAMES101】作业4 Bézier 曲线
wps插入图片后使图片完整显示
辉芒微IO单片机FT60F11F-MRB
VirtualLab基础实验教程-7.偏振(1)
Five reasons to choose SAP Spartacus as the implementation framework of SAP commerce cloud storefront