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

前端 未结 4 667
栀梦
栀梦 2021-01-05 05:45

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

   Thread.CurrentThread.CurrentCulture =
     Thread.CurrentThr         


        
4条回答
  •  鱼传尺愫
    2021-01-05 06:05

    first two Solutions works fine but what if we would like to extend this to any culture so i came up with this approach i change the current culture date time arrays into TitleCase

    private void SetDateTimeFormatNames()
            {
    
                Thread.CurrentThread.CurrentCulture.DateTimeFormat.DayNames = ConvertoToTitleCase(Thread.CurrentThread.CurrentCulture.DateTimeFormat.DayNames);
                Thread.CurrentThread.CurrentCulture.DateTimeFormat.MonthNames = ConvertoToTitleCase(Thread.CurrentThread.CurrentCulture.DateTimeFormat.MonthNames);
    
            }
    
    private string[] ConvertoToTitleCase(string[] arrayToConvert)
                {
                    for (int i = 0; i < arrayToConvert.Length; i++)
                    {
                        arrayToConvert[i] = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(arrayToConvert[i]);
                    }
    
                    return arrayToConvert;
                }
    

    how can this be improved with out the Loop?

提交回复
热议问题