php - 计算-1个月时的PHP天错误

标签 php date error-handling

当我在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/

相关文章:

javascript - moment.js 并在日历 View 中获取尾随日期

php - Wordpress 本地克隆无法正常工作

php - 如何在 Linux 上安装旧的 CURL(我有旧的 PHP 版本)

php - 将日期数组分成连续的 block

wpf - 在VB.net和WPF中处理异常

php - MAMP-mysqli_query(): (HY000/6): Error on delete of …

python - 如何在 Flask-restful 中返回错误消息?

javascript - 使用 PHP : Fatal error: Uncaught Error: Call to undefined function mysql_connect() 创建登录页面

javascript - 日期显示晚一天

java - 在 Java 中存储、检索和比较日期的最佳方式