根据开始时间和持续时间计算结束时间? [英] How do you calculate an end time based on start time and duration?

查看:1904
本文介绍了根据开始时间和持续时间计算结束时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个活动日历,并将开始时间传递给PHP,格式为2009-09-25 15:00:00。持续时间也可以通过,格式为60分钟或3小时。从小时转为分钟不是问题。您如何将一段时间添加到已建立的起始点以正确格式化结束时间?

I'm building a event calendar and pass a start time to PHP, in the format of 2009-09-25 15:00:00. A duration gets passed as well, that might be in the format of 60 minutes or 3 hours. Converting from hours to minutes isn't the problem. How do you add a length of time to an established starting point to correctly format the end time?

推荐答案

使用 strtotime(),您可以将当前时间(2009-09-25 15:00:00)转换为时间戳,然后添加(60 * 60 * 3 = 3hrs)到时间戳。最后只需将其转换回您想要的任何时间。

Using strtotime() you can convert the current time (2009-09-25 15:00:00) to a timestamp and then add (60 * 60 * 3 = 3hrs) to the timestamp. Finally just convert it back to whatever time you want.

//Start date
$date = '2009-09-25 15:00:00';
//plus time
$plus = 60 * 60 * 3;
//Add them
$time = strtotime($date) + $plus;
//Print out new time in whatever format you want
print date("F j, Y, g:i a", $time);

这篇关于根据开始时间和持续时间计算结束时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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