How can I convert a HH:mm:ss string to a JavaScript Date object?

前端 未结 3 1608
温柔的废话
温柔的废话 2020-12-17 01:55

I have dynamic string with a HH:mm:ss format (e.g. 18:19:02). How can the string be converted into a JavaScript Date object (in Internet Explorer 8

3条回答
  •  忘掉有多难
    2020-12-17 02:20

    Try this (without jQuery and a date object (it's only a time)):

    var
        pieces = "8:19:02".split(':')
        hour, minute, second;
    
    if(pieces.length === 3) {
        hour = parseInt(pieces[0], 10);
        minute = parseInt(pieces[1], 10);
        second = parseInt(pieces[2], 10);
    }
    

提交回复
热议问题