PHP strtotime在我的本地计算机上工作但在服务器上失败

PHP strtotime在我的本地计算机上工作但在服务器上失败

问题描述:

var_dump(strtotime("2012-W07 Monday")); 

returns int 1329170400 on my local computer (PHP Version 5.3.4) but on the server (PHP Version 5.1.6) it returns

bool(false)

Some other formats like "today", "now" etc. work properly on both sides. Is it because of php versions, or what else could be wrong?

  var_dump(strtotime(“2012-W07 Monday”));  
  code>  pre> 
 
 

在我的本地计算机(PHP Version 5.3.4)上返回 int 1329170400 code>但在服务器上(PHP Version 5.1.6)它 返回 p>

bool(false) p> blockquote>

其他一些格式,如“今天”,“现在”等 双方都做得很好。 是因为php版本,还是还有什么可能是错的? p> div>

I would expect this to be related to a minor feature improvement or a fixed bug. Not all updates/bugfixes make it to the PHP docs.

I would test it for you, but don't have an install lower than 5.3.1 available.

I think your best bet would be to somewhere grab a default PHP 5.1.6 and test on your local machine or another server. My bet is that it would fail there as well.

You can use 'YYYY-MM-DD' format with strtotime() and this format should work in all versions.

For the most stable behavior, I recomend passing only widely-used date-time formats to strtotime(). Be aware strtotime() expects a date separated by '/' to be in 'MM/DD/YYYY' format, which is the American order for dates. Europe uses a different order separated by '/'.