tempusdominus / bootstrap-4

Tempus Dominus Bootstrap 4 Datetime Picker
https://getdatepicker.com/5-4/
MIT License
611 stars 239 forks source link

Dateformat and C# MVC - Trying to help... #387

Open rhousham opened 1 year ago

rhousham commented 1 year ago

Hi unsure where this belongs, however if you are creating a new C# MVC application. In previous incarations of the datepicker the MMM format has returned back 3 digit months. This is still the case apart from September which returns back Sept.

C# Doesn't - out of the box - recognise this as a valid month/date. At least not in the Uk - great britain.

The fix - enter

<system.web>
`    <globalization uiCulture="en" culture="en-GB"/>`
</system.web>

In the web.config.

This seems to be down to the Intl.DateTimeFormat library and less tempusdominus - but thought I would save someone a job if they find this.

rhousham commented 1 year ago

Nope tell a lie - that didn't work...

rhousham commented 1 year ago

Seems like the fix is doing localization: { locale: 'en-US',//fix to make sure september is shortended to sep - rather than sept - which c# doesn't understand format: 'dd-MMM-yyyy' },

In the config

rhousham commented 1 year ago

Or update the c# Global.asax.cs and add

 System.Globalization.CultureInfo.DefaultThreadCurrentCulture = new System.Globalization.CultureInfo("en-GB");
            System.Globalization.CultureInfo.DefaultThreadCurrentCulture.DateTimeFormat.AbbreviatedMonthNames  = new string[] {
                "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec", ""
            };

It looks like basically there is a difference between c# microsoft and the javascript short months - hence causing issues.