Tôi có hai ngày
$date1 = "2014-02-11 04:04:26 AM"
$date2 = "2014-02-11 05:36:56 AM"
Tôi muốn tính toán sự khác biệt và hiển thị nó như sau
1 hour 32 minutes
hỏi ngày 11 tháng 2 năm 2014 lúc 4:08Feb 11, 2014 at 4:08
0
Sử dụng DateTime::diff
của lớp
This is a mandatory parameter as it specifies the start/first DateTime object.Làm thế nào tôi có thể tính tổng giờ trong PHP?This is a mandatory parameter as it specifies the end/second DateTime object. Có hai cách để tính tổng thời gian từ mảng. Sử dụng hàm strtotime []: hàm strtotime [] được sử dụng để chuyển đổi chuỗi thành định dạng thời gian. Các chức năng này trả về thời gian trong định dạng H: M: S. Ví dụ 1: Ví dụ này đọc các giá trị từ mảng và chuyển đổi nó thành định dạng thời gian.This function returns the difference between the first DateTime object and the second DateTime object otherwise it returns false on failure.
Làm thế nào có thể thêm giờ vài phút và giây trong PHP?The below program
illustrates the date_diff[] function to get the time difference in minutes.
PHP
$start = strtotime["12:00"]; $end = // Run query to get datetime value from db $elapsed = $end - $start; echo date["H:i", $elapsed]; ?>