最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to parse a string in jQuery - Stack Overflow

programmeradmin3浏览0评论

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!

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!

Share Improve this question edited Jun 19, 2010 at 4:20 alex 490k204 gold badges889 silver badges991 bronze badges asked Jun 19, 2010 at 4:15 dzmdzm 23.6k50 gold badges152 silver badges229 bronze badges 4
  • 6 what a ridiculous question. You do realise that jQuery isn't a language right? – SpliFF Commented Jun 19, 2010 at 4:19
  • 4 @SpliFF While you are right, I think a beginner may not know the difference. – alex Commented Jun 19, 2010 at 4:23
  • Especially based on how often they are told to use it on sites like this. – Aaron Butacov Commented Jun 19, 2010 at 5:57
  • Yes, I was unaware of JavaScripts split method - I mention jQuery simply because that's the framework I use. – dzm Commented Jun 19, 2010 at 13:04
Add a ment  | 

2 Answers 2

Reset to default 10
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)

  1. 暂无评论