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

239
Visualizações
Bootstrap datetimepicker - show custom AM/PM string

If I set my browser's language to Spanish (Mexico), then my C# culture datetime format displays the AM portion as "a. m." instead of the usual "AM".

I've tried using the localized moment.js formats of "L, LT, and LTS", but those don't give me the desired "a. m.". Next I tried passing down a datetime format (without the AM/PM portion, see dateTimeFormatInCulture below) from my C# code to the JavaScript and then appending the desired AM/PM on each time a datetime is selected. That partially worked, but then the time wasn't right in the afternoon because I was adding the AM/PM portion after the fact. Then I found the parseInputDate function option, but it looks like that won't work for what I want it to do.

        $("#dp").datetimepicker({
           daysOfWeekDisabled: [0, 1, 6],
           useCurrent: false,
           useSeconds: true,
           format: dateTimeFormatInCulture // "DD/MM/YYYY hh:mm:ss",
           parseInputDate: function(inputDate) {
            alert(inputDate);
            $("#txtBox").val(moment(inputDate).format(dateTimeFormatInCulture) + (amDisplay != "" ? " " + (moment(inputDate).hour() > 11 ? pmDisplay : amDisplay) : ""));
                return inputDate;
            }
        });

I've also used the changed.datetimepicker and a function fired when clicking on the icon to append the correct AM/PM value. It partially works but like I said above the time wasn't right in the afternoon.

    $('#dp').on("change.datetimepicker", ({date, oldDate}) => {
        var inputDate = moment(Date.parse(date));
            $("#txtBox").val(moment(inputDate).format(dateTimeFormatInCulture) + (amDisplay != "" ? " " + (moment(inputDate).hour() > 11 ? pmDisplay : amDisplay) : ""));
    });

    $('[data-toggle="datetimepicker"]').on('click', function() {
        var inputDate = moment(Date.parse($("#dp").datetimepicker("date")));
            $("#txtBox").val(moment(inputDate).format(dateTimeFormatInCulture) + (amDisplay != "" ? " " + (moment(inputDate).hour() > 11 ? pmDisplay : amDisplay) : ""));
    });

Is there a way to do what I want to do?

about 4 years ago · Juan Pablo Isaza
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