0
alert(end); //Wed Oct 22 2014 00:00:00 GMT+0200 (CEST)

How to display this in format dd.mm.yyyy ?

2 Answers2

2

Use built-in methods on the Date object

alert(end.getDate() + "." + (end.getMonth() + 1) + "." + end.getFullYear());

Note: I'm adding 1 to the month, because javascript returns the month in the range 0-11, with January being 0, February 1, etc.

Additional Note: I put parenthesis around that addition, because otherwise it would just do another string concatenation, so July 6, 2013 would become 6-61-2013 without the parenthesis

Jeremy T
  • 1,273
  • 1
  • 10
  • 14
  • 1
    `.getMonth()` goes from 0-11, so `alert(end.getDate() + "." + end.getMonth()+1 + "." + end.getFullYear());` – hwatkins Feb 28 '13 at 18:07
  • I probably want a colon instead of a period? Yeah, maybe, but in the question he said he wanted `dd.mm.yyyy`, so that's what I gave him :) – Jeremy T Feb 28 '13 at 18:08
  • Ah, he edited his comment since I replied to it. Good catch, I'll fix my response. – Jeremy T Feb 28 '13 at 18:11
  • `.getMonth()` goes from 0-11, so `alert(end.getDate() + "." + (end.getMonth()+1) + "." + end.getFullYear());` I didn't realize hitting enter on the comment saves it – hwatkins Feb 28 '13 at 18:15
1

If you don't mind the additional dependency, you could use Moment.js http://momentjs.com.

pdoherty926
  • 9,895
  • 4
  • 37
  • 68