本文介绍了在PHP中以H:i格式添加30分钟的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻正在做噩梦,只是看不到为什么它不起作用

Having a nightmare at the moment and just can't see why it isn't working

我有一个H:i形式的值(即10:00、13:30),等等,称为$ time

I have a value in the form H:i (ie 10:00, 13:30) etc called $time

我要创建两个新值,$ startTime(在$ time之前30分钟)和$ endTime(在$ time之后30分钟)

What I want to do is create two new values, $startTime which is 30 mins before $time and $endTime which is 30 mins after $time

我尝试了以下方法,但似乎不想工作

I have tried the following but just doesn't seem to want to work

$startTime = date("H:i",strtotime('-30 minutes',$time));
$endTime = date("H:i",strtotime('+30 minutes',$time));

如果我以$ time的时间经过10:00并回显$ startTime和$ endTime,我会得到:

If I pass through 10:00 as $time and echo out both $startTime and $endTime I get:

$startTime = 00:30
$startTime = 01:30

推荐答案

$time = strtotime('10:00');
$startTime = date("H:i", strtotime('-30 minutes', $time));
$endTime = date("H:i", strtotime('+30 minutes', $time));

这篇关于在PHP中以H:i格式添加30分钟的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 10:26