2

我是签名strftime("%e %B %Y", 1344557429)

它返回false但它应该"10 August 2012"根据http://php.net/manual/en/function.strftime.php以这种格式返回一个日期

问题可能出在哪里?

4

3 回答 3

4

先看说明书:

找到巨大的红框:

仅限 Windows:此函数的 Windows 实现不支持 %e 修饰符。为了达到这个值,可以使用 %#d 修饰符。下面的例子说明了如何编写一个跨平台兼容的函数。

虽然编写新代码是一种常见的做法,但将 error_reporting 设置为 E_ALL 以便您可以轻松找到错误。

于 2012-09-01T18:07:48.257 回答
2

对于单个日期使用:

$format = '%B '.((strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') ? '%#d' : '%e').', %Y';
$date = strftime($format, $unix_timestamp);

PHP docs 解决方案作为一个功能很好:

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/

于 2013-08-29T03:30:04.080 回答
0

啊,找到了解决方案,感谢@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);
?>
于 2012-09-01T18:08:59.747 回答