Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override the moment js default invalid date text

How can I override the moment.js

var defaultInvalidDate = 'Invalid date';

without changing the moment.js file. Just like my site overrides certain bootstrap css styles with a Site.css, so when bootstrap is updated I dont lose the changes, is there any way to make overrides for momentjs?

Thanks in advance

like image 725
Alan Ball Avatar asked Sep 14 '25 12:09

Alan Ball


1 Answers

Just update your current locale used by moment.js using moment.updateLocale(localeName, config)

moment.updateLocale(moment.locale(), { invalidDate: "Invalid Date Updated" })

Here is the working example:

console.log(moment(new Date("Aa")).format(""));
moment.updateLocale(moment.locale(), { invalidDate: "Invalid Date Updated" })
console.log(moment(new Date("Aa")).format(""));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
like image 71
Adnan Umer Avatar answered Sep 16 '25 02:09

Adnan Umer