获取当前日期和日期两个月后在php [英] get current date and date after two months in php

查看:84
本文介绍了获取当前日期和日期两个月后在php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常跛脚的问题,但我无法找到这个问题。
如何在两个月后获得今天的日期和日期。

this is a very lame question but i m not able to find this one. How to get today's date and date after two months..

格式是月日期年(数字)。

format is month-date-year (numerical.)

推荐答案

您可以使用 strtotime()函数:

$today = time();
$twoMonthsLater = strtotime("+2 months", $today);

// If what you really want is exactly 60 days later, then
$sixtyDaysLater = strtotime("+60 days", $today);
// ...or 8 weeks later :
$eightWeeksLater = strtotime("+8 weeks", $today);

无论如何,生成的新时间戳可以转换为月日期年: p>

In any case, the resulting new timestamps can then be converted to month-date-year :

echo 'Today is : ' . date('m-d-Y', $today);
echo 'Two months later will be : ' . date('m-d-Y', $twoMonthsLater);

** 更新 **

PHP手册


注意:请注意,这些功能取决于服务器的区域设置。确保使用夏令时(使用例如$ date = strtotime('+ 7天',$ date)而不是$ date + = 7 * 24 * 60 * 60),并在使用这些功能时考虑到闰年。 / p>

Note: Please keep in mind that these functions are dependent on the locale settings of your server. Make sure to take daylight saving time (use e.g. $date = strtotime('+7 days', $date) and not $date += 7*24*60*60) and leap years into consideration when working with these functions.

只是想我应该提到它...

Just thought I should mention it...

这篇关于获取当前日期和日期两个月后在php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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