首页 新闻 赞助 找找看

php怎么取一个未来的时间点

0
悬赏园豆:100 [待解决问题]

用php怎么取一个未来的时间点,我的需求是:

 

比如现在是2014-3-10 22:31

我想得到一个$time=明天的上午10点整(2014-3-11 10:00)

也就是说,不管我现在的时间是几点,我只要取到这个日期就好,然后加上一天,第二天的10点就是我要的准确日期。

 

大牛们有办法没?

php的哦~

Tony Zhao的主页 Tony Zhao | 初学一级 | 园豆:102
提问于:2014-03-10 22:35
< >
分享
所有回答(2)
1

This function allows the addition of day(s),month(s),year(s) to the original date while still preserving the Hours, minutes and seconds
You can also modify to add to hours, miuntes and even seconds.
 
<?php
function add_date($givendate,$day=0,$mth=0,$yr=0) {
      $cd = strtotime($givendate);
      $newdate = date('Y-m-d h:i:s', mktime(date('h',$cd),
    date('i',$cd), date('s',$cd), date('m',$cd)+$mth,
    date('d',$cd)+$day, date('Y',$cd)+$yr));
      return $newdate;
              }

?>

爱编程的大叔 | 园豆:30839 (高人七级) | 2014-03-10 23:20
0

主要用strtotime函数,可以看看手册。

date('Y-m-d H:i:s', strtotime(date('Y-m-d')." 10:00:00 +1 day"))

yuaccp2 | 园豆:202 (菜鸟二级) | 2014-03-11 09:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册