-5

I have data available in ISO format which is 2021-06-01T00:00:00.000Z. I want to convert it into 1st June 2021 format.

Below is what I did

 const dat = 2021-06-06T00:00:00.000Z;
 const d = new Date(dat);
 console.log(d.toDateString());result 

I am getting this Tue Jun 01 2021. How can I format this into desired format?

halfer
  • 19,824
  • 17
  • 99
  • 186
Digvijay
  • 2,887
  • 3
  • 36
  • 86
  • 3
    This question covers just about every possible approach to date-formatting: [How do I format a date in JavaScript?](https://stackoverflow.com/questions/3552461/how-do-i-format-a-date-in-javascript) – DBS Jan 11 '23 at 10:05
  • *"Below is what I did"*: That's not valid JavaScript (add quotes?) – trincot Jan 11 '23 at 10:06
  • [Searching for that exact title](https://duckduckgo.com/?q=How+to+format+date+in+specified+format+in+Javascript) has all you need to answer your question -> [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) – Andreas Jan 11 '23 at 10:09
  • Please take note of the 5 downvotes and change your course, Digivay. **All** of your questions need repair when they are posted. How about saving volunteers some work and writing them carefully to start with? – halfer Feb 10 '23 at 17:53
  • Sentences should end with a full stop and then a space. Don't omit the full stop (these are known as "run-on sentences"). Don't omit the space (this is known as "unreadable"). Omit chat, waffle, conversion, and filler. Please make an effort - you have been here long enough. – halfer Feb 10 '23 at 17:54

1 Answers1

0

You can use moment.js libary for date conversion.

let yourDate = "2021-06-06T00:00:00.000Z";
let convertedDate = moment(yourDate).format("Do MMMM YYYY");
console.log("Result (6th June 2021) ==>>", convertedDate)
<script type = "text/JavaScript" src = "https://MomentJS.com/downloads/moment.js"></script>
Sachin Dane
  • 248
  • 2
  • 6
  • 1
    _"We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done."_ -> https://momentjs.com/docs/#/-project-status/ – Andreas Jan 11 '23 at 10:41