Tempus Dominus changes PM to AM when user opens picker

36 Views Asked by At

UPDATE: Actually the problem is when the user clicks the date field, the value is changed to the current date time. How do I stop that?

Using TD v6.9.4 Passing DateTime object from .Net MVC 6. The date and time show correctly, but when the user clicks on the date field, the picker opens and is set to 'AM' regardless.

$(".timepicker").each(function () {
    var elementId = $(this).attr("id");
    new tempusDominus.TempusDominus(document.getElementById(elementId), {
        localization: {
            dateFormats: {
                LLL: 'MM/dd/yyyy h:mm T',
            },
            format: 'LLL',
        },
        display: {
            icons: {
                type: 'icons',
                today: 'bi bi-calendar-check',
                time: 'bi bi-clock',
                up: 'bi bi-arrow-up',
                down: 'bi bi-arrow-down',
                previous: 'bi bi-arrow-left',
                next: 'bi bi-arrow-right',
                clear: 'bi bi-trash-fill',
                close: 'bi bi-x'
            },
            sideBySide: true,
            keepOpen: false,
            buttons: {
                today: true,
                clear: true,
                close: true
            },
            components: {
                decades: true,
                clock: true,
                hours: true,
                minutes: true,
            },
            inline: false,
            theme: 'light'
        }
    });
});

enter image description here

After clicking:

enter image description here

Date object as it leaves the MVC Controller:

enter image description here

The value even shows correctly in chrome dev tools:

enter image description here

How to I get the AM/PM to read correctly?

I have tried changing the date format in the js code and I have tried passing the date as a formatted string using "DataFormatString" in my model, neither have helped.

1

There are 1 best solutions below

0
BattleFrog On

I fixed this by changing the formatting in my Model

from: [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy hh:mm T}")]

to: [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy hh:mm tt}")]