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?
Asked
Active
Viewed 341 times
-1

Om3ga
- 30,465
- 43
- 141
- 221
2 Answers
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