0

I want to get following date format (by JavaScript only) - March 3, 2020

var date = new Date();
console.log(date);

Currently I am getting in "2020-05-11T10:08:43.322Z" format. Kindly, help!

Deadpool
  • 6,416
  • 5
  • 32
  • 64
  • You've only created a date, but haven't tried to format it. Why don't you try it first and look in to the [docs at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) on what you can use to do it? – Emiel Zuurbier May 11 '20 at 10:14
  • Does this answer your question? [How to format a JavaScript date](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – Jsowa May 11 '20 at 10:22

2 Answers2

4

You can check Date.prototype.toLocaleString for more information

var date = new Date();
console.log(date.toLocaleString('en-US', {month: 'long', day: 'numeric', year: 'numeric'}));
Hao Wu
  • 12,323
  • 4
  • 12
  • 39
1

You can use moment.js

let date = moment().format('MMMM DD, YYYY');
console.log(date)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.1/moment.min.js" integrity="sha256-zG8v+NWiZxmjNi+CvUYnZwKtHzFtdO8cAKUIdB8+U9I=" crossorigin="anonymous"></script>
Narendra Chouhan
  • 2,140
  • 1
  • 9
  • 17