本文介紹了在 PHP 中減去時間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我已經尋找了幾個小時的答案,但我找不到.
我正在編寫一個簡單的腳本
.用戶設置他們的工作開始和結束時間.例如,有人從 8:00 到 16:00 工作.我怎樣才能減去這個時間,看看這個人工作了多長時間?
我正在嘗試 strtotime();
但沒有成功...
解決方案
以下內容更好一些:
<前>$a = new DateTime('08:00');$b = new DateTime('16:00');$interval = $a->diff($b);echo $interval->format("%H");這會給你帶來小時數的差異.
I have been looking for an answer for a few hours now, but I can't find one.
I'm writing a simple script
. The user sets their work start and end time. So, for example, somebody is working from 8:00 to 16:00.
How can I subtract this time to see how long the person has been working?
I was experimenting with strtotime();
but without success...
解決方案
A bit nicer is the following:
$a = new DateTime('08:00'); $b = new DateTime('16:00'); $interval = $a->diff($b); echo $interval->format("%H");
That will give you the difference in hours.
這篇關于在 PHP 中減去時間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!