나는 단순히 DateTime
구조 를 사용하여 1에서 12 사이의 정수를 축약 된 월 이름으로 변환 하려고했습니다 .
내가 시도한 것은 다음과 같습니다.
DateTime getMonth = DateTime.ParseExact(Month.ToString(),
"M", CultureInfo.CurrentCulture);
return getMonth.ToString("MMM");
그러나 FormatException
문자열이 유효하지 않기 때문에 첫 번째 줄에 표시 DateTime
됩니다. 누구든지이 작업을 수행하는 방법을 말해 줄 수 있습니까?
답변
답변
var monthIndex = 1;
return month = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(monthIndex);
이것도 시도해 볼 수 있습니다
답변
대신 이와 같이 할 수 있습니다.
return new DateTime(2010, Month, 1).ToString("MMM");
답변
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(
Convert.ToInt32(e.Row.Cells[7].Text.Substring(3,2))).Substring(0,3)
+ "-"
+ Convert.ToDateTime(e.Row.Cells[7].Text).ToString("yyyy");
답변
