I am getting date in following format
20.04.2013 09:33:34
I want to make it as 2013.04.20 09:33:34
Any ideas how to do this using javascript or jquery?
I am getting date in following format
20.04.2013 09:33:34
I want to make it as 2013.04.20 09:33:34
Any ideas how to do this using javascript or jquery?
Split by a space or period. Then take the appropriate sections and combine them together like so:
var s = "20.04.2013 09:33:34".split(/[ .]/)
console.log(s[2] + '.' + s[1] + '.' + s[0] + ' ' + s[3]);
No need for any external libraries or to load it into a Date
object.
You can achieve this by using Moment.js:
var date = moment("20.04.2013 09:33:34", "DD.MM.YYYY HH:mm:ss");
date.format("YYYY.MM.DD HH:mm:ss")
// "2013.04.20 09:33:34"
Need to do this
var date = "20.04.2013 09:33:34".split(/[ .]/);
var newData = date[2] + "." + date[1] + "." + date[0] + " " + date[3];
console.log(newData); // Outputs: "2013.04.20 09:33:34"