Issue
This is the format i got
2019-01-08T11:11:00.000Z
This is the format i want
2019-01-08
How can i format date like that?
Note: I don't want moment package
Solution
Use the Date
constructor to create the new date object from your date string. Then you can create the date in any custom format using this object. See the code below.
const input = "2019-01-08T11:11:00.000Z";
const dateObj = new Date(input);
const year = dateObj.getFullYear();
const month = (dateObj.getMonth()+1).toString().padStart(2, '0');
const date = dateObj.getDate().toString().padStart(2, '0');
const result = `${year}-${month}-${date}`;
console.log(result);
Answered By - Vivek
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.