0

I just want to know how can i format date in java script. I have date string is.

2015-04-21T09:31:04+05:00

I need to convert this 21 April, 2015 Can any one help me ?

Thanks

Abdul Basit
  • 161
  • 1
  • 1
  • 11
  • 1
    possible duplicate with [how to format a Date in MM/dd/yyyy HH:mm:ss format in javascript?](http://stackoverflow.com/questions/10632346/how-to-format-a-date-in-mm-dd-yyyy-hhmmss-format-in-javascript) & [Where can I find documentation on formatting a date in JavaScript](http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – Kyojimaru Apr 22 '15 at 07:58

2 Answers2

0

Use JavaScript Date object.

var date = new Date("2015-04-21T09:31:04+05:00");
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
console.log(date.getDate() + ' ' + months[date.getMonth()] + ', ' + date.getFullYear());
Sumit
  • 1,619
  • 1
  • 11
  • 24
  • 1
    `console.log(date.getDate() + ' ' + months[date.getMonth()] + ', ' + date.getFullYear());` You need to add `,` to obtain the said format!! – Guruprasad J Rao Apr 22 '15 at 08:02
0

If you are open to libraries and you plan to "heavily" use Date you have MomentJS which would do it easily:

moment().format('MMMM Do YYYY');  // April 22nd 2015
//or
moment("2015-04-21T09:31:04+05:00").format('MMMM Do YYYY'); // April 21nd 2015
Outpox
  • 129
  • 1
  • 10