php / php/php-src

Unexpected Results with PHP8 date_diff for Different Timezones

Đang mở
#13,857 3 bình luận 1 reaction 1 người được giao Xem trên GitHub

@derickr đang làm issue này rồi.

Từ ngày 1/4/2024.

Bug Extension: date Status: Verified
Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.