简体   繁体   中英

JavaScript Add hh:mm + hh:mm to get new hh:mm

I have two javascript vars (they're coming from text boxes, so they're probably being evaluated as strings) in this format: 02:30 and 4:45

they represent hours and minutes.

I want to add them together to get 07:15 but I can't figure it out.

Split on the colon. Sum the minutes. Divide by 60 and round to get hours and modulo to get minutes. Add the hours to the other total hours. Cast the integers as strings and concatenate to get the new time.

我已经开始使用Date.js( http://www.datejs.com/ )并且发现它可以使这样的事情变得更容易。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM