Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change date picker text: capitalize month

Tags:

c#

datepicker

I want to change the date picker by upper-casing the first letter of the month.

Currently I'm using the set culture info in the thread and specify the format there, but for my culture the month is always all lowercase:

CultureInfo ci = new CultureInfo("es-MX");
ci.DateTimeFormat.ShortDatePattern = "ddd dd/MMM/yyyy";
Thread.CurrentThread.CurrentCulture = ci;

Displays:

Dom 19/ago/2012

And I would like to have:

Dom 19/Ago/2012

How can I change that?

like image 958
OscarRyz Avatar asked Aug 19 '12 16:08

OscarRyz


2 Answers

Specifying the AbbreviatedMonthGenitiveNames, AbbreviatedMonthNames along with the ShortDatePattern did the trick.

Thread.CurrentThread.CurrentCulture = new CultureInfo("es-MX")
{
    DateTimeFormat = new DateTimeFormatInfo
    {
        AbbreviatedMonthGenitiveNames = new string[] { "Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic", string.Empty },
        AbbreviatedMonthNames         = new string[] { "Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic", string.Empty },
        ShortDatePattern = "ddd dd/MMM/yyyy"
    }
};

Yields:

enter image description here

Edit:

I have to add:

...
AbbreviatedDayNames = new string[] { "Dom",  "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb"},

Too

like image 181
OscarRyz Avatar answered Sep 18 '22 01:09

OscarRyz


You could probably use the CultureAndRegionInfoBuilder class to copy the existing culture and change only the month names. Then you subsequently use that culture in your application instead of the CultureInfo you now use.

Note however, that CultureAndRegionInfoBuilder is in the sysglobl.dll assembly, which you'll need to import.

like image 40
Daniel A.A. Pelsmaeker Avatar answered Sep 19 '22 01:09

Daniel A.A. Pelsmaeker