You could extend the Number class to allow for zero padding (to display single-digit days and months with zeroes in the front):
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
The pad function takes an optional size parameter which dictates the total length of the number string with the default value of 2.
You could then update your existing code to split the date into three components (using the pad function when printing the result):
var createdDate = new Date('2013-01-21 01:23:44');
var date = createdDate.toLocaleDateString();
var day = createdDate.getDate();
var month = createdDate.getMonth() + 1; //months are zero based
var year = createdDate.getFullYear();
var time = createdDate.toLocaleTimeString().replace(/(.*)\D\d+/, '$1');
console.log(year + '-' + month.pad() + '-' + day.pad() + ' ' + time);
If you are looking for more elegant or less verbose solutions, you will need to use external libraries.