strtotime从windows(localhost)转移到linux(webhost)时计算错误

时间:2011-05-26 09:55:37

标签: php

我在使用简单的PHP函数在我的网站空间上工作时遇到了一些问题,同时它在我的本地服务器服务器上的工作方式与预期的一样。

问题是以下计算:

echo $Formated = date("Ymd",strtotime("last day of next month"));

这个脚本看起来似乎没有用b / c我只是在我的服务器上运行它时得到默认日期19691231而不是正确的20110630

我使用windows(XAMP)作为我的本地主机服务器,所以我想在两种平台处理它的方式中必定存在某种形式的问题?

3 个答案:

答案 0 :(得分:3)

strtotime因跨版本而出了问题,所以我建议大量简化。您可以使用日期格式中的't'字符来表示该月的最后一天,然后减少您的strtotime调用,只需返回下个月的某个时间戳。

echo $Formated = date("Ymt", strtotime("next month"));

答案 1 :(得分:1)

如果没有给出月份名称,请不要使用of

尝试

 date('m/d/y', strtotime('last day next month')); 

 OR

 date('m/d/y', strtotime('last day of march'));  // give the month name with of

Reference

答案 2 :(得分:0)

忘记迁移和部署,实际上strtime不可靠。浏览PHP的官方网站:查看strtotime manual, especially this comment

如果您有可用的MySQL连接,SELECT DATE_ADD('2011-05-31',INTERVAL 1 MONTH)将不那么多余,因为(正确的)功能已经实现,您无需自己实现它。