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?