我只是尝试使用DateTime
结构将1到12之间的整数转换为缩写的月份名称。
这是我尝试过的:
DateTime getMonth = DateTime.ParseExact(Month.ToString(),
"M", CultureInfo.CurrentCulture);
return getMonth.ToString("MMM");
但是,我在第一行得到了一个FormatException
,因为该字符串不是有效的DateTime
。有人能告诉我怎么做吗?
发布于 2014-01-28 16:14:17
var monthIndex = 1;
return month = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(monthIndex);
你也可以试试这个
发布于 2011-06-09 08:38:05
你可以这样做。
return new DateTime(2010, Month, 1).ToString("MMM");
发布于 2015-01-08 22:29:24
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");
https://stackoverflow.com/questions/6286868
复制相似问题