why does strftime() on windows returns false? (i'm not using %e)

时光毁灭记忆、已成空白 提交于 2019-12-10 15:44:30

问题


Here is my code:

var_dump(strftime("%m-%d-%Y %l:%M:%S", time()));
echo "<br />";
var_dump(strftime("%Y-%d-%m %H:%M:%S", time()));

The first line returns false, and the third returns the anticipated string '2012-10-09 23:03:18' (length=19)

Why is the first line returning false?

I'm running windows 7x64 and wamp with fairly default settings.


回答1:


If the first line doesn't work but the second one does, then the reason is obviously because of %l

var_dump(strftime("%l", time()));

Does indeed throw errors on windows.

Reading the manual on strftime...

Not all conversion specifiers may be supported by your C library, in which case they will not be supported by PHP's strftime(). Additionally, not all platforms support negative timestamps, so your date range may be limited to no earlier than the Unix epoch. This means that %e, %T, %R and, %D (and possibly others) - as well as dates prior to Jan 1, 1970 - will not work on Windows, some Linux distributions, and a few other operating systems. For Windows systems, a complete overview of supported conversion specifiers can be found at » MSDN.

Therefore %l is clealy one not supported.




回答2:


While coming across this on my local WAMP server, I found a solution for %l not working. Following the fix of %e, which is %#d, I testing using %#I for an hour without preceding 0 and it worked flawlessly. So you can use this is your code:

var_dump(strftime("%m-%d-%Y %#I:%M:%S", time()));

Unfortunately, this does not work in a linux environment, it will output #I instead of the hour.



来源:https://stackoverflow.com/questions/12362179/why-does-strftime-on-windows-returns-false-im-not-using-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!