Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MomentJS time in spanish

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?

like image 763
Alpha2k Avatar asked Jun 15 '15 10:06

Alpha2k


People also ask

How do I change timezone in MomentJS?

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();

How do I get the current time in MomentJS?

To get the current date and time, just call javascript moment() with no parameters like so: var now = moment();

What is MomentJS used for?

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.

What can I use instead of MomentJS?

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).


2 Answers

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')); 
like image 156
Alpha2k Avatar answered Sep 25 '22 06:09

Alpha2k


The following method worked for me

moment(agreement.dateStart).locale('es').format('LLLL')
like image 41
Guillermina Galache Avatar answered Sep 25 '22 06:09

Guillermina Galache