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

10,632

Solution 1

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!.

Solution 2

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".

Share:
10,632
Oscar Cabrero
Author by

Oscar Cabrero

i have 5+ years experience in developing Enterprise .net solutions, i work for Softtek Near Shore Services in Ensenada Mexico, I'm 24. In Lake'ch im Another You.

Updated on June 05, 2022

Comments

  • Oscar Cabrero
    Oscar Cabrero almost 2 years

    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?

  • Jeff Yates
    Jeff Yates over 15 years
    This is not a good approach when your I18Ning your work as it requires intimate knowledge of translations.
  • jfs
    jfs over 15 years
    yeah my bad. But how would you approach in culture ignostic way?
  • jaircazarin-old-account
    jaircazarin-old-account over 15 years
    Hey that's true. I'm Mexican I didn't know that the correct way was using lower case. In Mexico many people write months and days using title case, probably because of an US influence
  • dvdmn
    dvdmn about 10 years
    if using Microsoft's translation is ok for you you can use Thread.CurrentThread.CurrentCulture = new CultureInfo("es-ES");
  • DustinA
    DustinA over 7 years
    The problem with using es-ES is that number formatting is different between Mexico and Spain. You'll get commas instead of periods for the decimal, and decimals where you expect commas.
  • ElektroStudios
    ElektroStudios over 6 years
    Worst function name ever. Spanglish is Evil.