Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda