duanqin4238 2013-01-04 22:22
浏览 72
已采纳

在php中转换日期,toString函数不起作用

I'm trying to convert a date to a string by using the toString('dd MMMM YYY') function. But here, this isn't working.

Here is my code:

    $date_start = new Zend_Date(strtotime($this->startdate));
    echo($date_start); 

The result is: 31 Dec 2012 00:00:00

    $date_input = $date_start->toString('dd MMMM YYY');
    echo($date_input);

The result is: 31 December 2013

What do I have to do to obtain 31 December 2012 ?

  • 写回答

2条回答 默认 最新

  • douhe1002 2013-01-04 22:28
    关注

    This is a known issue described here: http://framework.zend.com/issues/browse/ZF-5297

    Note that the default ISO format differs from PHP's format which can be irritating if you have not used in previous. Especially the format specifiers for Year and Minute are often not used in the intended way.

    For year there are two specifiers available which are often mistaken. The Y specifier for the ISO year and the y specifier for the real year. The difference is small but significant. Y calculates the ISO year, which is often used for calendar formats. See for example the 31. December 2007. The real year is 2007, but it is the first day of the first week in the week 1 of the year 2008. So, if you are using 'dd.MM.yyyy' you will get '31.December.2007' but if you use 'dd.MM.YYYY' you will get '31.December.2008'. As you see this is no bug but a expected behaviour depending on the used specifiers.

    Use "yyy" instead of "YYY".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号