Reputation: 79
So I'm using Timestamps in Mongoose but the format is this: 2021-12-09T08:35:44.189Z
, but I don't want to show this way, instead what I want is: 9 December 2021
.
What is the approach to it? as I haven't found any.
Upvotes: 0
Views: 114
Reputation: 11156
The fastest way is to use moment.js
. One-line solution:
console.log(moment('2021-12-09T08:35:44.189Z').format('D MMMM YYYY'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
Upvotes: 1
Reputation: 411
If you will do it by your self , first you can use new Date("2021-12-09T08:35:44.189Z")
to get the timeStemp of this date ,and then , use the api:
getFullYear
、 getMonth
、getDate()
to get the year、month and date ,then join it by yourself;
let timeStamp = new Date('2021-12-09T08:35:44.189Z');
let year = timeStamp.getFullYear(),
month = timeStamp.getMonth(),
date = timeStam.getDate();
or you can also use the third-party like day.js to help you do the same thing
Upvotes: 1