gpt4 book ai didi

php - 在php中获取当前日期和两个月后的日期

转载 作者:可可西里 更新时间:2023-11-01 13:36:03 27 4
gpt4 key购买 nike

这是一个非常蹩脚的问题,但我找不到这个问题。如何获取今天的日期和两个月后的日期..

格式为月-日-年(数字。)

最佳答案

您可以使用 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);

在任何情况下,生成的新时间戳都可以转换为月-日-年:

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

** 更新 **

来自PHP manual

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.

只是觉得我应该提一下...

关于php - 在php中获取当前日期和两个月后的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3642652/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com