Reputation: 23534
I'd like to parse the following string which is a time (HH:MM:SS): 00:00:00
Does anyone know how I can get the Hour, Minute, or Seconds values?
Thank you!
Upvotes: 3
Views: 7916
Reputation: 1517
var time = "00:00:00";
var parts = time.split(':');
alert("hours: " + parts[0] + ", minutes: " + parts[1] + ", seconds: ", + parts[2])
Upvotes: 10
Reputation: 60580
I'd probably go with the split(':') solution myself, but here's an interesting alternative using the native Date parsing:
var time = '00:23:54';
var date = new Date('1/1/1900 ' + time);
// 0
date.getHours();
// 23
date.getMinutes();
// 54
date.getSeconds();
Upvotes: 4