user1809790
user1809790

Reputation: 1369

Format Stopwatch Timer

I am using a jQuery stopwatch that outputs time in the format: 02:45:03. However, I need to save the value in the database as minutes. Can anyone tell me how I can convert such a value into minutes? Or, are you aware of any stopwatch that I can use that displays the time in minutes and I would be able to toggle it (pause/resume) and delete instance completely?

Upvotes: 0

Views: 503

Answers (1)

Kevin Boucher
Kevin Boucher

Reputation: 16675

You can use a fake date to parse the time string into a Date object; and then use the Date object's methods to extract the hours and minutes and add them together:

var time = "02:45:03",
    date = new Date( "1/1/1970 " + time ),
    minutes = date.getHours() * 60 + date.getMinutes();

alert( minutes );

Upvotes: 3

Related Questions