加上"x"小时数 [英] Add 'x' number of hours to date

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

问题描述

我目前有php像这样返回当前日期/时间:

I currently have php returning the current date/time like so:

$now = date("Y-m-d H:m:s");

我想做的是有一个新变量$new_time等于$now + $hours,其中$hours是从24到800的小时数.

What I'd like to do is have a new variable $new_time equal $now + $hours, where $hours is a number of hours ranging from 24 to 800.

有什么建议吗?

推荐答案

您可以使用.

如果函数中需要变量,则必须使用双引号,然后使用strtotime("+{$hours} hours"),但是最好使用strtotime(sprintf("+%d hours", $hours)).

If you need variables in the function, you must use double quotes then like strtotime("+{$hours} hours"), however better you use strtotime(sprintf("+%d hours", $hours)) then.

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

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