StackOverflow StackOverflow - 5 months ago 23
Javascript Question

How to convert digits in format "hhmmss" to time format hh:mm:ss using javascript?

I have string like

and i want to change it to time format like
(like date format of type string) using javascript or jquery. How can i do this work?


You can easily split string to two-digit numbers using regex in String.prototype.match() that return values in array. Then use Array.prototype.join() to joins items of array into string.

var str = "080000";
str = str.match(/\d{2}/g).join(":");