Search code examples
momentjsmoment-timezone

moment-timezone format es local, return "Fecha inválida" not valid


I am using moment-timezone and I am trying to format the date like this:

moment('dic. 23 2020  11:00').format('YYYY-MM-DD HH:mm');

I am getting that it's not valid?

any idea why?


Solution

  • Try specifying the format parameter, after specifying the locale info. Have a look at this

    const moment = require("moment");
    require("moment/min/locales.min");
    moment.locale("es");
    const result = moment("dic. 23 2020  11:00", "MMM[.] DD YYYY hh:mm").format("YYYYMM-DD HH:mm");
    console.log(result);