Trừ hai lần PHP
Trong hướng dẫn này, chúng ta sẽ học Cách trừ giờ khỏi thời gian trong PHP. Tôi sẽ giải thích một cách dễ dàng để tạo PHP trừ giờ từ thời điểm hiện tại. Bạn đã hiểu cách trừ giờ ra khỏi thời gian trong PHP. Vì vậy, hãy thảo luận về cách trừ giờ từ thời điểm hiện tại trong PHP Show Cũng đọc. Cách trừ phút theo thời gian trong PHP Ở đây, tôi sẽ cung cấp hai ví dụ
Tôi sẽ cho bạn một ví dụ đơn giản về cách trừ giờ từ thời gian trong PHP. Tại đây, hãy tạo một ví dụ đơn giản về việc trừ 2 giờ so với thời gian hiện tại trong PHP Trong bài viết này, chúng ta sẽ xem cách tính chênh lệch giữa 2 ngày trong PHP, cùng với việc hiểu triển khai của nó thông qua các ví dụ. Đưa ra hai ngày tức là. , start_date và end_date & chúng ta cần tìm sự khác biệt giữa hai ngày Xem xét ví dụ dưới đây Input: start_date: 2016-06-01 22:45:00 end_date: 2018-09-21 10:44:01 Output: 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds Explanation: The difference of 2 dates will give the date in complete format. Phương pháp 1. Sử dụng hàm date_diff() Hàm này được sử dụng để tìm sự khác biệt giữa hai ngày. Hàm này sẽ trả về một đối tượng DateInterval nếu thành công và trả về FALSE nếu thất bại Thí dụ. Ví dụ này minh họa việc sử dụng hàm date_diff() để tính chênh lệch giữa 2 ngày PHP
+2 years 3 months0 +2 years 3 months1
+2 years 3 months3 = date_create( +2 years 3 months5 +2 years 3 months1
+2 years 3 months8
2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds1 $datetime1 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds3 +2 years 3 months3 +2 years 3 months1
2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds7
2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds9 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds0 Difference between two dates: 1031 Difference between two dates: 1032 +2 years 3 months1 Difference between two dates: 1034 đầu ra +2 years 3 months Phương pháp 2. Để sử dụng công thức toán học ngày-giờ để tìm sự khác biệt giữa hai ngày. Nó trả về năm, tháng, ngày, giờ, phút, giây giữa hai ngày được chỉ định Thí dụ. Trong ví dụ này, chúng ta sẽ sử dụng công thức toán học ngày-thời gian để tính chênh lệch giữa các ngày sẽ được trả về theo năm, tháng, ngày, giờ, phút, giây PHP
Difference between two dates: 1037
________ 101 _______________ 105 _______ 6
+2 years 3 months06 $datetime1 1+2 years 3 months08
+2 years 3 months10
+2 years 3 months12
+2 years 3 months14
+2 years 3 months24 // Creates DateTime objects 0$datetime1 1+2 years 3 months27 = date_create( 8+2 years 3 months29 +2 years 3 months30_______1_______31
+2 years 3 months33
+2 years 3 months35
+2 years 3 months37
+2 years 3 months47_______102_______0 $datetime1 1+2 years 3 months27 = date_create( 8+2 years 3 months52 +2 years 3 months53 // Creates DateTime objects 0+2 years 3 months16 +2 years 3 months56
+2 years 3 months33
+2 years 3 months60
+2 years 3 months47_______102_______0 $datetime1 1+2 years 3 months27 = date_create( 8+2 years 3 months52 +2 years 3 months76 // Creates DateTime objects 0+2 years 3 months16 +2 years 3 months79 +2 years 3 months39 +2 years 3 months81
+2 years 3 months83
+2 years 3 months85_______1_______86 +2 years 3 months87 +2 years 3 months88 +2 years 3 months89 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds3 // Creates DateTime objects 82 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds3 $datetime1 12 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds3 +2 years 3 months06 = date_create( 82 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds3 +2 years 3 months16 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds3 +2 years 3 months39 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds3 +2 years 3 months62 +2 years 3 months1 Difference between two dates: 1034 đầu ra 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds Phương pháp 3. Phương pháp này được sử dụng để lấy tổng số ngày giữa hai ngày được chỉ định PHP
2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds07
2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds23
2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds25
2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds27
2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds9 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds30 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds31 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds32 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds16 // Creates DateTime objects 02 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds09 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds36 Difference between two dates: 1034 đầu ra Difference between two dates: 103 PHP là ngôn ngữ kịch bản phía máy chủ được thiết kế dành riêng cho phát triển web. Bạn có thể học PHP từ đầu bằng cách làm theo Hướng dẫn PHP và Ví dụ về PHP này Làm cách nào để trừ hai lần trong PHP?$time1 = $row_TicketRS['OpenTime']; . 30 //$Giờ =sàn((($t2 - $t1)/60)/60);
Làm cách nào để thêm hai lần trong PHP?Cách dễ nhất để cộng hai lần bằng php là. . Chuyển đổi thời gian từ H. i. s (e. g. 08. 15. 40) sang giây làm tương tự cho lần thứ hai giá trị ref. bước 1 thêm các giá trị đã chuyển đổi và lưu trữ nó biến php Bây giờ chuyển đổi tổng số (tính bằng giây) thành H. i. s Làm cách nào để trừ hai lần trong laravel?Làm cách nào để tính giờ giữa hai lần trong PHP?php $time1 = strtotime('08. 00. 00'); . 30. 00'); . Đoạn mã trên sẽ làm tròn thành phút. Lưu câu trả lời này. Note: The code above will round to minutes. Save this answer. |