从 _GET 添加一小时 [英] Add one hour from _GET

查看:42
本文介绍了从 _GET 添加一小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 date('H', strtotime($_GET['h'].' +1 hours')) ($_GET['h'] 包含我从 URL 获得的小时,即 20 为 20:00)但它只在应该打印 21 时打印 01.我想得到这个小时,然后再加一个小时,这样 20 就是 21,依此类推.

I'm using date('H', strtotime($_GET['h'].' +1 hour')) at the moment ($_GET['h'] contains the hour I'm getting from the URL, i.e. 20 as in 20:00) but it only prints 01 when it should print 21. I want to get this hour and add one hour to it so 20 will be 21 and so on.

我在这里做错了什么?

推荐答案

这样的事情应该可行:

$time = DateTime::createFromFormat('H:i', '20:00');
$time->modify('+1 hour');
echo $time->format('H:i');

查看实际操作

这篇关于从 _GET 添加一小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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