我有一个数据库表,将餐厅的营业时间以时间格式存储为时间范围。例如,如果餐厅的营业时间是‘上午9点到下午5点’,那么将有两列'hours_open‘和'hours_close’,我将9:00存储在'hours_open‘中,将17:00存储在' hours _close’中。我需要做的是显示时间范围例如:上午9:30上午10:00上午10:30上午11:00上午11:30到下午5:00
有谁能给我指个方向吗?
发布于 2011-11-25 07:08:42
$start = strtotime('6:00am');
$end = strtotime('09:00am');
$range = array();
while ($start !== $end)
{
$start = strtotime('+30 minutes',$start);
$range[] = date('h:ia', $start);
}
print_r($range);发布于 2011-11-25 06:54:26
谁能给我指个方向?
当然,这是你需要的一切:
发布于 2018-12-21 01:24:33
在我目前的项目中,我不得不在一天的24小时内循环……并希望它们以特定的格式显示。
$interval = new DateInterval('PT1H'); // creating the interval for 1hour
$date = new DateTime();
$end = clone($date);
$hoursRange = new DatePeriod($date, $interval ,$end->modify("+24 hours"));然后,我所拥有的就是使用hoursRange遍历foreach值。
foreach ($hoursRange as $key => $value)
{
echo $value->format('ga');
}https://stackoverflow.com/questions/8263143
复制相似问题