开发者

Add and Subtract Time

开发者 https://www.devze.com 2022-12-29 00:57 出处:网络
I have always had a problem with adding and subtracting time like for an example: 10h:34min + 07h:46min

I have always had a problem with adding and subtracting time like for an example:

   10h:34min 
 + 07h:46min
 -------开发者_C百科----
    XX:XX


Convert your time(s) to minutes, add them and re-calculate hours and minutes:

time in minutes ("tim"): (10 * 60 + 34) + (7 * 60 + 46)
result: floor(tim/60) : (tim%60)

floor(tim/60) will give you the whole hours
tim%60 is the "modulo" which is the integer "rest" of (tim/60)

If you work with whole dates (and times, not durations like it seems you do), try mktime and/ or strtotime which support operations like "+10 minutes" (and other).

0

精彩评论

暂无评论...
验证码 换一张
取 消