php如何划分时间 [英] how to divide time php

查看:57
本文介绍了php如何划分时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将时间除以一个整数值:

I want to divide time to an integer value:

1-> 6.15AM till 7.00AM
2-> 7.00AM till 7.45AM
3-> 7.45AM till 8.30AM
4-> 8.30AM till 9.15AM
------BREAK----------- 15 minutes
5-> 9.30AM till 10.15AM
6-> 10.15AM till 11.00AM
7-> 11.00 till 11.45AM
-------BREAK---------- 15 minutes
8-> 12.00 till 12.45PM
9-> 12.45PM till 1.30PM
10-> 1.30PM till 02.15PM

任何人都可以帮助我...?之前谢谢...!

Anyone can help me...? thanks before..!

推荐答案

试试吧,你可能需要稍微改变一下范围(我懒得做精确的计算)

Try, you might have to change the ranges a bit (i am too lazy to do the exact calculation)

$time = time(); // or if your time is in string format use $time = strtotime('10:15 AM');
$seconds_elapsed = $time % 86400; // Seconds since midnight
$mins_elapsed = $seconds_elapsed / 60;
$mins_split = floor($mins_elapsed  / 15); // Split into 15 mins intervals

if ( $mins_split >= 25 && $mins_split <= 36) {
    $index = ($mins_split - 25) / 3;
} elseif ($mins_split >= 38 << $mins_split <= 47) {
    $index = ($mins_split - 38) / 3;
} else {
    $index = ($mins_split - 48) / 3;
}

这篇关于php如何划分时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆