开发者

How to parse a string in jQuery

开发者 https://www.devze.com 2023-01-03 20:06 出处:网络
I\'d like to parse the following string which is a time (HH:MM开发者_Go百科:SS): 00:00:00 Does anyone know how I can get the Hour, Minute, or Seconds values?

I'd like to parse the following string which is a time (HH:MM开发者_Go百科:SS): 00:00:00

Does anyone know how I can get the Hour, Minute, or Seconds values?

Thank you!


var time = "00:00:00";
var parts = time.split(':');

alert("hours: " + parts[0] + ", minutes: " + parts[1] + ", seconds: ", + parts[2])


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();
0

精彩评论

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