I have a date timestamp coming in this format 2021-02-08T19:36:47.000+0000
. How can I format this in JavaScript in DD-MM-YYYY Hh:mm
format.
Asked
Active
Viewed 60 times
-1

user14765755
- 43
- 8
-
8Does this answer your question? [How to format a JavaScript date](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – Wendelin Feb 19 '21 at 08:19
-
1This [Link](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) might help you as this is answered before. – kunal panchal Feb 19 '21 at 08:19
2 Answers
1
Download moment.js
and include to your file
then you can use like this
moment("2021-02-08T19:36:47.000+0000).format("DD-MM-YYYY Hh:mm")
I usually use this in my every project https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js

Mukti Prasad Behera
- 269
- 1
- 6
-1
This is plain Javascript
// 2021-02-08T19:36:47.000+0000
function formatDate(date) {
var d = new Date(date),
minutes = ':' + d.getMinutes(),
hours = ' ' + d.getHours(),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = '-' + d.getFullYear();
if (month.length < 2) {
month = '-0' + month;
} else if (month.length < 3) {
month = '-' + month;
}
if (day.length < 2)
day = '0' + day;
// DD-MM-YYYY HH:mm
return [day, month, year, hours, minutes].join('');
}
console.log(formatDate("2021-02-08T19:36:47.000+0000"))

ru4ert
- 998
- 2
- 14
- 25