添加'x'到目前为止的小时数 [英] Add 'x' amount of hours to date

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

问题描述

我目前有php获取当前时间/日期如下:

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

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

想要做的是有一个新的变量 $ new_time 等于 $ now + $ hours $ hours 的使用时间范围为24-800。

What id like to do is have a new variable $new_time equal $now + $hours. $hours being an amount of hours ranging anywhere from 24-800.

任何建议?

推荐答案

您可以使用类似 strtotime() 功能为当前时间戳添加一些东西。 $ new_time = date(Ymd H:i:s,strtotime('+ 5 hours'))

如果您需要在函数中使用变量,则必须使用双引号,如 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天全站免登陆