Steven Kwok Steven Kwok - 10 days ago 6
Javascript Question

Javascript timestamp formatting with regular expression?

how do i format a string of 2014-09-10 10:07:02 into something like this:

2014,09,10,10,07,02

Thanks!

Answer

var str = "2014,09-10 10:07:02";

var newstr = str.replace(/["\-"," ",":"]/g, ',');

console.log(newstr);

Nice and simple.

var str = "2014,09-10 10:07:02";
var newstr = str.replace(/["\-"," ",":"]/g, ',');
console.log(newstr);
Comments