How do I change the language of the "momentjs" plugin?

0

I have tried in a thousand ways that I have seen in SOEn, but none of them helps me.

Here is an example of what I'm trying to do:

    $( document ).ready(function() {
      console.log(moment(new Date('2017-03-16')).format('dddd MMMM D'));
    });
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/locale/es.js"></script>
    
    

Here it works perfectly, but in my system NO, why would that happen? I'm working with the same cdn that I put in the example.

    
asked by Pablo Contreras 18.03.2017 в 05:03
source

1 answer

2

Well I already found something, what should be specified in a clear way, so that the library, know that when you use moment.lang("es") or any language then it works for you anywhere.

moment.lang('es', {
  months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
  monthsShort: 'Enero._Feb._Mar_Abr._May_Jun_Jul._Ago_Sept._Oct._Nov._Dec.'.split('_'),
  weekdays: 'Domingo_Lunes_Martes_Miercoles_Jueves_Viernes_Sabado'.split('_'),
  weekdaysShort: 'Dom._Lun._Mar._Mier._Jue._Vier._Sab.'.split('_'),
  weekdaysMin: 'Do_Lu_Ma_Mi_Ju_Vi_Sa'.split('_')
);

This way you can customize all the formats as you want, the function split that is at the end of each line indicates that after each _ is a different format.

    
answered by 18.03.2017 / 05:42
source