I am using the next code to convert a date received from a MySQL database format 1993-10-23 00:00:00
and display it in spanish:
alert(moment('1993-10-23 00:00:00', 'YYYY-MM-DD', 'es'));
23 oct is saturday. I would expect to get sábado
but I get the next:
Sat Oct 23 1993 00:00:00 GMT+0200
Also tried adding: moment.locale('es-ES');
, moment.locale('en-ES');
and moment.locale('es');
but neither works.
What's the correct way of converting dates from a language to another?
To change the default time zone, use moment.tz.setDefault with a valid time zone. moment.tz.setDefault("America/New_York"); To reset the default time zone to local, use moment.tz.setDefault with no arguments. moment.tz.setDefault();
To get the current date and time, just call javascript moment() with no parameters like so: var now = moment();
MomentJS is a JavaScript library which helps is parsing, validating, manipulating and displaying date/time in JavaScript in a very easy way. This chapter will provide an overview of MomentJS and discusses its features in detail. Moment JS allows displaying of date as per localization and in human readable format.
And today, the most popular alternative to Moment. js is Day. js which surpassed date-fns on GitHub by stars (46,2k Day. js stars vs 37,7k date-fns stars).
This seems to work, thanks @RobG
var localLocale = moment('1993-10-23 00:00:00');
moment.locale('es');
localLocale.locale(false);
alert(localLocale.format('LLLL'));
The following method worked for me
moment(agreement.dateStart).locale('es').format('LLLL')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With