Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

strtotime - Adding 30 minutes to time formatted as H:i in PHP

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

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

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));

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

$startTime = 00:30
$startTime = 01:30        
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
$time = strtotime('10:00');
$startTime = date("H:i", strtotime('-30 minutes', $time));
$endTime = date("H:i", strtotime('+30 minutes', $time));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...