Unexpected Results with PHP8 date_diff for Different Timezones

未关闭
#13,857 3 条评论 1 个 reaction 已指派 1 人 在 GitHub 查看

@derickr 已经在做这个了。

开始于 2024年4月1日。

评估

这个 Issue 还没有评估数据。

描述

Bug Extension: date Status: Verified
Description

In PHP 8.1.25, running date_diff against different time zones returned unexpected results.

https://3v4l.org/RFQMt

The following code:

<?php
date_default_timezone_set('Asia/Tokyo');
$nowDate = (new DateTime('2024-04-01 00:49:22'))->setTimeZone(new DateTimeZone('Asia/Tokyo'));
$endDate = (new DateTime('2024-04-01 08:48:22'))->setTimeZone(new DateTimeZone('UTC'));
echo date_diff($nowDate, $endDate)->format('%Y-%M-%D %H:%I:%S');

Resulted in this output:

-1-11-31 07:59:00

But I expected this output instead:

00-00-00 07:59:00
PHP Version

PHP 8.1.25

Operating System

Ubuntu 22.04

主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 15 小时
30 天内合并 PR
103

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。