StackOverflow StackOverflow - 1 month ago 5
jQuery Question

how to add colon in between the string as a date display pattern of type string

80000

to

8:00:00

I want the above

80000
string type to change to display as
8:00:00
(like date format of type string)

Answer

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(":");
console.log(str);