dtvnbe1428 2013-01-31 13:16
浏览 49
已采纳

Zend_Date,ISO_8601,日期解析和本地系统时钟

I have a strange problem with Zend_Date object.

It seems that setters perform different operations with different system clock dates. Let's assume that system date is 28 January 2013, following code:

$now=new Zend_Date(Zend_Date::ISO_8601);
$now->now();
echo '<br/>now: ' . $now->toString();
echo '<br/>now->day: ' . $now->get(Zend_Date::DAY);
echo '<br/>now->month: ' . $now->get(Zend_Date::MONTH);
echo '<br/>now->year: ' . $now->get(Zend_Date::YEAR);
$end=new Zend_Date('2013-02-25 14:23:34', Zend_Date::ISO_8601);
echo '<br/>end: ' . $end->toString();
$end->setHour('23')->setMinute('59')->setSecond('59')->setDay($now->get(Zend_Date::DAY))->setMonth($now->get(Zend_Date::MONTH))->setYear($now->get(Zend_Date::YEAR));
echo '<br/>endAfterSetters: ' . $end->toString();

will produce following output:

now: 28-01-2013 14:04:28
now->day: 28
now->month: 01
now->year: 2013
end: 25-02-2013 14:23:34
endAfterSetters: 28-01-2013 23:59:59

But if you change system clock to 29 January 2013, output is different from expectations:

now: 29-01-2013 14:07:22
now->day: 29
now->month: 01
now->year: 2013
end: 25-02-2013 14:23:34
endAfterSetters: 01-01-2013 23:59:59

Last output is 01-01-2013 23:59:59, but should be 29-01-2013 23:59:59 !

It happens on PHP 5.3.2 and 5.3.16, Zend_Framework 10.7, latest Zend_Date 24880 version.

Everyting worked fine in the past.

Any ideas why it happens?

P.S.: I have also found jquery datatime plugin malfunciton while using it at 29,30,31 January... But i will describe it in other question.

  • 写回答

1条回答 默认 最新

  • dsjgk330337 2013-01-31 13:43
    关注

    Remember that your setters are called in sequence. So when you call setDay(29) you're telling it to change the date to 29th February 2013, which isn't a valid date, so it's rolling that over to make it 1st March 2013. Then you call setMonth(1), which changes the month to January, giving you 1st January 2013.

    You can control this behaviour by passing the extend_month option to the Zend_Date constructor, see: http://framework.zend.com/manual/1.12/en/zend.date.overview.html#zend.date.options.extendmonth

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line