0

How can i get date having format Dec 27 2017 from iso date?

MY ISO date is

2017-12-27 00:00:00

How can i get this

Dec 27 2017

  • sorry i this is August 27 2017 – user3648363 Sep 10 '17 at 05:02
  • 1
    Possible duplicate of [How to format a JavaScript date](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – Nisarg Sep 10 '17 at 05:03
  • Note: The question I am flagging as duplicate is not an exact duplicate, but it does show everything you need to get to your answer. – Nisarg Sep 10 '17 at 05:03
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString `var options = { year: 'numeric', month: 'short', day: 'numeric' }; new Date('2017-12-27 00:00:00Z').toLocaleDateString('en-US',options);` – Kaiido Sep 10 '17 at 05:08

1 Answers1

1

Here's how you could do this.

function formatDate(date) {
  var monthNames = [
    "Jan", "Feb", "Mar",
    "Apr", "May", "Jun", "Jul",
    "Aug", "Sep", "Oct",
    "Nov", "Dec"
  ];

  var day = date.getDate();
  var monthIndex = date.getMonth();
  var year = date.getFullYear();

  return monthNames[monthIndex] + ' ' +day + ' ' + year;
}

console.log(formatDate(new Date())); // show current date-time in console

Ref: How to format a JavaScript date

Nisarg
  • 13,121
  • 5
  • 31
  • 48
  • Instead of posting an answer to the duplicate question (which you've linked twice now), cast a close vote or flag it as a duplicate. Posting another answer isn't beneficial to the site, when there's a perfectly suitable existing answer. – Ken White Sep 10 '17 at 05:45