.net에서 정수를 월 이름으로 바꾸는 가장 좋은 방법이 있습니까?
분명히 날짜 시간을 돌려서 문자열을 만들고 거기에서 월 이름을 구문 분석 할 수 있습니다. 그것은 엄청난 시간 낭비처럼 보입니다.
답변
DateTimeFormatInfo에서 GetMonthName 시도
http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.getmonthname.aspx
다음과 같이 할 수 있습니다.
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
답변
왜 그냥 사용하지 somedatetime.ToString("MMMM")
않습니까?
답변
올바른 네임 스페이스 및 개체로 업데이트되었습니다.
//This was wrong
//CultureInfo.DateTimeFormat.MonthNames[index];
//Correct but keep in mind CurrentInfo could be null
DateTimeFormatInfo.CurrentInfo.MonthNames[index];
답변
Microsoft.VisualBasic
네임 스페이스 에서 정적 메서드를 사용할 수 있습니다 .
string monthName = Microsoft.VisualBasic.DateAndTime.MonthName(monthInt, false);
답변
DateTime dt = new DateTime(year, month, day);
Response.Write(day + "-" + dt.ToString("MMMM") + "-" + year);
이렇게하면 월이 정수가 아닌 이름으로 표시됩니다.
답변
약식 월 값을 얻으려면 다음을 사용할 수 있습니다. Enum.Parse();
Enum.Parse(typeof(Month), "0");
결과적으로 “Jan”이 생성됩니다.
이것은 0부터 시작하는 인덱스라는 것을 기억하십시오.
답변
![](http://daplus.net/wp-content/uploads/2023/04/coupang_part-e1630022808943-2.png)