StackOverflow StackOverflow - 1 month ago 8
Javascript Question

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

I have string like

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

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

Comments