strtotime 函数输出错误,如何解决?
strtotime function giving wrong output, How to solve?
我在我的项目中使用了php strtotime函数并且它工作正常,但是今天有用户报告了一个问题,我检查发现 strtotime 函数没有给出正确的输出。
我的代码是:
echo date('M Y', strtotime('-1 month'));
正在给出输出:
Mar 2017 instead of Feb 2017
我在代码在线工具上检查了上面的代码,它在那里给出了相同的输出,所以是 php 核心功能问题还是我做错了什么?
注意:我在网上查了下面的代码
echo date('Y-m-d', strtotime('-1 month'));
它的输出让我很奇怪
2017-03-02
date("M Y", strtotime("-1 months"));
这是真的,但今天是 3 月 30 日,这就是为什么您没有得到您想要的确切结果的原因。所以,我们应该使用每月的第一天,然后应用减法。
我在我的项目中使用了php strtotime函数并且它工作正常,但是今天有用户报告了一个问题,我检查发现 strtotime 函数没有给出正确的输出。 我的代码是:
echo date('M Y', strtotime('-1 month'));
正在给出输出:
Mar 2017 instead of Feb 2017
我在代码在线工具上检查了上面的代码,它在那里给出了相同的输出,所以是 php 核心功能问题还是我做错了什么? 注意:我在网上查了下面的代码
echo date('Y-m-d', strtotime('-1 month'));
它的输出让我很奇怪
2017-03-02
date("M Y", strtotime("-1 months"));
这是真的,但今天是 3 月 30 日,这就是为什么您没有得到您想要的确切结果的原因。所以,我们应该使用每月的第一天,然后应用减法。