I am working on an Angular 5 project where I am converting dates to moment objects using the following code:
moment(date).add(1, 'd').toDate()
When dealing with Spanish locale and a date string like '31/7/2018'
, the moment(date)
function gives me an error saying Invalid da
. However, upon checking the moment instance, I confirmed that the locale is correctly set to es
. To load the locale data in moment, I am using the following code:
import * as moment from 'moment';
import 'moment/locale/es'
moment.locale(languageWithRegion);
In my .angular-cli.json
file, I have included the scripts for jQuery, Bootstrap, Moment.js, and its locales. The version of Moment.js I am using is 2.22.1
.
Despite all this setup, I am still facing issues with the import statement. Any help would be greatly appreciated.