Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to uppercase date and month first letter of ToLongDateString() result in es-mx Culture?

currently i obtain the below result from the following C# line of code when in es-MX Culture

   Thread.CurrentThread.CurrentCulture =
     Thread.CurrentThread.CurrentUICulture = new
                CultureInfo("es-mx");

  <span><%=DateTime.Now.ToLongDateString()%></span>

miércoles, 22 de octubre de 2008

i would like to obtain the following

Miércoles, 22 de Octubre de 2008

do i need to Build my own culture?

like image 362
Oscar Cabrero Avatar asked Oct 23 '08 04:10

Oscar Cabrero


2 Answers

You don't need to build your own culture. You only need to change the property DateTimeFormat.DayNames and DateTimeFormat.MonthNames in the current culture.

i.e.

        string[] newNames = { "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado", "Domingo" };
        Thread.CurrentThread.CurrentCulture.DateTimeFormat.DayNames = newNames;

However, it's weird that en-US show months and days with the first uppercase letter and for mx-ES not.

Hope it helps!.

like image 160
jaircazarin-old-account Avatar answered Sep 27 '22 16:09

jaircazarin-old-account


The pattern of LongDate for Spanish (Mexico) is

dddd, dd' de 'MMMM' de 'yyyy

according to Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongDatePattern. I guess you just have to manually convert the initial letters of the day and month to uppercase or you can use Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase and then replace "De" with "de".

like image 43
jfs Avatar answered Sep 27 '22 15:09

jfs