-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,709
  • 5
  • 36
  • 63

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
  • 92,051
  • 24
  • 178
  • 169
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
  • 39,785
  • 13
  • 117
  • 123
-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
  • 92,051
  • 24
  • 178
  • 169
Ed Heal
  • 57,599
  • 16
  • 82
  • 120