I used date picker which is in dd/mm/yyyy format. For saving this date in mongodb database I converted this date into number Long format and save it. I want to display all records in dd/mm/yyyy format then how can I convert number long to date in dd/mm/yyyy format?
Asked
Active
Viewed 735 times
1 Answers
0
try this function
function getDateIfDate(d) {
var m = d.match(/\/Date\((\d+)\)\//);
return m ? (new Date(+m[1])).toLocaleDateString('en-US', {month: '2-digit', day: '2-digit', year: 'numeric'}) : d;
}
console.log(getDateIfDate("/Date(1460008501597)/"));
console.log(getDateIfDate('abc'));

Jay
- 703
- 9
- 21