views:

31

answers:

2

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.

+2  A: 

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.

Peter Loron
You will probably need to cast the split strings to integers as well to specify addition for the split numbers. +1
jaywon
A: 

I've started working with Date.js (http://www.datejs.com/) and have found it to make things like this a lot easier.

BradBrening