我是usign strftime("%e %B %Y", 1344557429)
它返回false,但根据http://php.net/manual/en/function.strftime.php,它应该返回格式为"10 August 2012"的日期
你知道问题出在哪里吗?
发布于 2012-09-02 02:07:48
先阅读手册:
找到巨大的红色方框:
仅限
窗口:在此函数的窗口实现中不支持 %e修饰符。若要获得此值,可以改用%#d修饰符。下面的例子说明了如何编写跨平台兼容的函数。
虽然编写新代码是一种常见的做法,但将error_reporting设置为E_ALL,这样您就可以很容易地找到错误。
发布于 2013-08-29 11:30:04
对于单个日期,请使用:
$format = '%B '.((strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') ? '%#d' : '%e').', %Y';
$date = strftime($format, $unix_timestamp);PHP文档解决方案是一个很好的函数:
function fixed_strftime($format, $unix_timestamp) {
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
$format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format);
}
return strftime($format, $unix_timestamp);
}来源:http://codeitdown.com/php-strftime-e-on-windows/
发布于 2012-09-02 02:09:00
啊,找到了解决方案,感谢@Peter Szymkowski。我是盲人
<?php
// Jan 1: results in: '%e%1%' (%%, e, %%, %e, %%)
$format = '%%e%%%e%%';
// Check for Windows to find and replace the %e
// modifier correctly
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
$format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format);
}
echo strftime($format);
?>https://stackoverflow.com/questions/12230112
复制相似问题