대문자 날짜 및 월 첫 글자 Tolongdatestring ()의 첫 글자는 ES-MX 문화를 초래합니까?
-
04-07-2019 - |
문제
현재 ES-MX 문화에서 다음 C# 코드 라인에서 아래 결과를 얻습니다.
Thread.CurrentThread.CurrentCulture =
Thread.CurrentThread.CurrentUICulture = new
CultureInfo("es-mx");
<span><%=DateTime.Now.ToLongDateString()%></span>
Miércoles, 22 De Octubre de 2008
다음을 얻고 싶습니다
Miércoles, 22 De Octubre de 2008
내 문화를 구축해야합니까?
해결책
자신의 문화를 구축 할 필요가 없습니다. 현재 문화에서 속성 DateTimeFormat.dayNames 및 DateTimeFormat.MonthNames 만 변경하면됩니다.
즉
string[] newNames = { "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado", "Domingo" };
Thread.CurrentThread.CurrentCulture.DateTimeFormat.DayNames = newNames;
그러나 EN-US가 첫 번째 대문자와 MX-EES와 함께 몇 달과 며칠을 보여주는 것이 이상합니다.
도움이되기를 바랍니다!.
다른 팁
스페인어 (멕시코)의 Longdate 패턴은
dddd, dd' de 'MMMM' de 'yyyy
~에 따르면 Thread.currentthread.currentCulture.datetimeformat.longdatepattern. 요일과 월의 초기 문자를 대문자로 수동으로 변환해야한다고 생각합니다. Thread.currentthread.currentCulture.textInfo.totitleCase 그런 다음 "de"를 "de"로 바꾸십시오.
처음 두 솔루션은 잘 작동하지만이 방법을 어떤 문화로 확장하고 싶다면이 접근법을 생각해 내고 현재 문화 날짜 시간 배열을 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;
}
루프 밖으로 어떻게 개선 할 수 있습니까?
조금 늦었지만 이것은 나를 위해 일합니다!
public static string GetFecha()
{
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("es-EC");
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
// maldita sea!
string strDate = culture.TextInfo.ToTitleCase(DateTime.Now.ToLongDateString());
return strDate.Replace("De", "de");
}
제휴하지 않습니다 StackOverflow