dragon201401 2012-02-29 13:14
浏览 99
已采纳

PHP IntlDateFormatter格式返回错误的日期

I'm getting incorrect results using IntlDateFormatter:

$dateFormater = \IntlDateFormatter::create(
'en_EN',
\IntlDateFormatter::LONG,
\IntlDateFormatter::NONE
);

$a = date('Y/m/d H:i:s',1332712800); //2012/03/26 00:00:00
$b = $dateFormater->format(1332712800); //March 25, 2012

But this only happens for dates between 2012/03/26 and 2012/10/28 and without hour (00:00:00).

I can't find out what is the problem.

Thanks for the help.

  • 写回答

1条回答 默认 最新

  • dongzhen7108 2012-02-29 16:14
    关注

    http://userguide.icu-project.org/datetime/timezone#TOC-Factory-Methods-and-the-Default-Tim says

    TimeZone maintains a static time zone object known as the default time zone. This is the time zone that is used implicitly when the user does not specify one. ICU attempts to match this to the host OS time zone.

    In short, if you want to change the default timezone from intl to match what date() says, you must change the time zone on your operating system. But don't do that.

    It is preferred that you specify the timezone in the call to IntlDateFormatter::create(). If you wish to use the default timezone that PHP is using elsewhere, that can be retrieved with date_default_timezone_get().

    $dateFormater = \IntlDateFormatter::create(
        'en_EN',
        \IntlDateFormatter::LONG,
        \IntlDateFormatter::NONE,
        date_default_timezone_get()
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP