Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!