PHP获取未来的日期时间 [英] php get future date time

查看:36
本文介绍了PHP获取未来的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道该如何正确地解释这个问题,而只是为您提供一些示例,这样您才能真正得到我想说的话.

I don't know how to explain this correctly but just some sample for you guys so that you can really get what Im trying to say.

今天是2010年4月9日

Today is April 09, 2010

从现在起7天是2010年4月16日

7 days from now is April 16,2010

我正在寻找一个php代码,它可以给我确切的日期,并给出当前日期之前的天数.

Im looking for a php code, which can give me the exact date giving the number of days interval prior to the current date.

我一直在寻找一个可以解决甚至提示如何解决该问题的线程,但我没有找到.

I've been looking for a thread which can solve or even give a hint on how to solve this one but I found none.

推荐答案

如果您使用的是PHP> = 5.2,我强烈建议您使用新的DateTime对象,它使处理日期变得更加容易:

If you are using PHP >= 5.2, I strongly suggest you use the new DateTime object, which makes working with dates a lot easier:

<?php
$date = new DateTime("2006-12-12");
$date->modify("+7 day");
echo $date->format("Y-m-d");
?>

这篇关于PHP获取未来的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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