-1

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?

James
  • 1,827
  • 5
  • 39
  • 69

3 Answers3

1

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.

David Sherret
  • 101,669
  • 28
  • 188
  • 178
1

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"
gustavohenke
  • 40,997
  • 14
  • 121
  • 129
-1

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"
David Sherret
  • 101,669
  • 28
  • 188
  • 178
Ed Heal
  • 59,252
  • 17
  • 87
  • 127