zend 日期和夏令时

发布于 2024-11-10 03:32:07 字数 772 浏览 0 评论 0原文

我对冬季/夏季时间交叉的日期有问题。请参阅示例

        $pickUpDate = '2011-10-23';
        $dropOffDate = '2011-10-31';
        $pickUpTime = '09:00';
        $dropOffTime = '09:00';

        Zend_Date::setOptions(array('fix_dst' => false));
        Zend_Date::setOptions(array('fix_dst' => false));
        $pickUpDateTime = new Zend_Date ( $pickUpDate);
        $pickUpDateTime->setTime ( $pickUpTime );
        $dropOffDateTime = new Zend_Date ( $dropOffDate);
        $dropOffDateTime->setTime ( $dropOffTime );


        $dateDiff = ceil(($dropOffDateTime->getTimestamp ( ) - $pickUpDateTime->getTimestamp ( )) / (3600 * 24));
        echo $dateDiff;

Echo 生成 9...我的时区是伦敦,但我认为 fix_dst 应该解决夏季问题?我也尝试过将时区设置为 GMT 和 UTC 但有相同的效果吗?有什么想法吗?

I have a issue with dates crossing from winter/summer time.. please see example

        $pickUpDate = '2011-10-23';
        $dropOffDate = '2011-10-31';
        $pickUpTime = '09:00';
        $dropOffTime = '09:00';

        Zend_Date::setOptions(array('fix_dst' => false));
        Zend_Date::setOptions(array('fix_dst' => false));
        $pickUpDateTime = new Zend_Date ( $pickUpDate);
        $pickUpDateTime->setTime ( $pickUpTime );
        $dropOffDateTime = new Zend_Date ( $dropOffDate);
        $dropOffDateTime->setTime ( $dropOffTime );


        $dateDiff = ceil(($dropOffDateTime->getTimestamp ( ) - $pickUpDateTime->getTimestamp ( )) / (3600 * 24));
        echo $dateDiff;

Echo produces 9... My Timezone is London, but I thought the fix_dst should fix the summertime issue? I have also tried to set timezone to GMT and UTC but has the same effect? any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云归处 2024-11-17 03:32:07

时间戳没有时区信息。您应该避免将它们用于此用例。

可能您应该尝试在您的2 个日期。这将处理夏令时。

另请检查您的时区,因为根据我从上面的链接中读到的内容:

如果您的实际时区在
Zend_Date 的实例设置为 UTC 或
GMT 选项“fix_dst”将不会
使用是因为这两个时区确实
不适用于 DST。

Timestamps do not have Timezone information. You should avoid using them for this use case.

May be you should try with Zend_Date::sub method between your 2 dates. This will take care of DST.

Please also review your timezone because from what I read from the link above :

If your actual timezone within the
instance of Zend_Date is set to UTC or
GMT the option 'fix_dst' will not be
used because these two timezones do
not work with DST.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文