Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
How to convert moment.js date format 'LLL' to 'YYYY-MM-DD'

How can i change format of moment.js date? I use locales format ('LLL') in datatables columnDefs render and trying to filter date column with external filter inputs. When i format input value with 'LLL', logical operators doesn't work correct. So maybe if i convert column data, it will work. Theese are my codes:

"render": function (data) {
                        var locale = lang;
                        return (moment(data).isValid()) ? moment(data).locale(locale).format("LLL") : "-";

and filtering is:

$.fn.dataTableExt.afnFiltering.push(
            function (oSettings, aData, iDataIndex) {
                var filterstart = $('#start').val();
                var filterend = $('#end').val();
                var datecolumn = 5;
                var tabledatestart = aData[datecolumn];
                var tabledateend = aData[datecolumn];

                var locale = lang;
                filterstart = (moment(filterstart).isValid()) ? moment(filterstart).locale(locale).format('LLL') : "";
                filterend = (moment(filterend).isValid()) ? moment(filterend).locale(locale).format('LLL') : "";

                if (filterstart === "" && filterend === "") {
                    return true;
                }
                else if ((filterstart==tabledatestart || filterstart<tabledatestart) && filterend === "") {
                    return true;
                }
                else if ((filterstart==tabledatestart || filterstart>tabledatestart) && filterstart === "") {
                    return true;
                }
                else if ((filterstart==tabledatestart || filterstart<tabledatestart) && (filterend==tabledateend || filterend>tabledateend)) {
                    return true;
                }
                return false;
            }
        );
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Make sure to use moment with locales and set the locale before parsing the date.

moment.locale('tr_TR');

console.log(
  moment('6 Ocak 2022 12:45', 'LLL').format('YYYY-MM-DD')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment-with-locales.min.js"></script>

I'm pretty sure that the locale needs to be set first before parsing, as the following returns 'Invalid Date':

console.log(
  moment('6 Ocak 2022 12:45', 'LLL').locale('tr_TR').format('YYYY-MM-DD')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment-with-locales.min.js"></script>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda