-1

I have a date like var string = 2013-02-22. I want to convert it into 22.02.2013. How can I do it in JavaScript?

Om3ga
  • 30,465
  • 43
  • 141
  • 221

2 Answers2

1

If you just want to change the textual representation of the date you can use a regular expression:

var string = '2013-02-22';
var patt = /(\d\d\d\d)-(\d\d)-(\d\d)/;
var dates = patt.exec(string);

if (dates && dates.length === 4) {
    alert(dates[3] + '.' + dates[2] + '.' + dates[1]);
}
snedkov
  • 309
  • 2
  • 6
0

You could use datejs. It is a free open-source javascript library for working with dates.

thitemple
  • 5,833
  • 4
  • 42
  • 67