0

How can one get a date in the following format?

"Mon, May 2, 2016"

I have a function called formatDate(day, month year)

I want to call it like this

formatDate(2,5,2016) 

and get the previous string.

I would also like to know how to get a date in the following format:

May 2016

I would like to call it like this:

formatMonth(2,5,2016)
Stephen H. Anderson
  • 792
  • 1
  • 12
  • 32
  • I guess that depends on the implementation of `formateDate`. What does it currently return? Does it allow you to specify the format? – Felix Kling May 07 '16 at 01:35
  • Use [Moment.js](http://momentjs.com/). – Michał Perłakowski May 07 '16 at 01:36
  • Also: [How to format a JavaScript date](http://stackoverflow.com/q/3552461/218196) – Felix Kling May 07 '16 at 01:39
  • function formatDate(day, month, year) { var date = new Date(year, month - 1, day); date = date.toDateString().split(' '); return date[0] + ', ' + date[1] + ' ' + Number(date[2]) + ', ' + date[3]; } function formatMonth(day, month, year) { var date = new Date(year, month - 1, day); date = date.toDateString().split(' '); return date[1] + ' ' + date[3]; } – Rodrigo5244 May 07 '16 at 01:49
  • @Waterscroll your answer is the one I was looking for! – Stephen H. Anderson May 07 '16 at 01:58

0 Answers0