当我在PHP日期计算中遇到问题时,我感到惊讶。
$add = '- 30 days';
echo date('Y-m-01', strtotime($add)); // result is 2017-02-01 which is correct as need
但在
$add = '-1 month';
echo date('Y-m-01', strtotime($add)); // result is 2017-03-01 which is in correct
请帮我解决这个问题。
最佳答案
您可以看一下:http://php.net/manual/en/function.strtotime.php(说明和评论)
Note:
Using this function for mathematical operations is not advisable. It is better to use DateTime::add() and DateTime::sub() in PHP 5.3 and later, or DateTime::modify() in PHP 5.2.
关于php - 计算-1个月时的PHP天错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43111741/