asp.net mvc 3 - c# is there a easy way to convert month integer to name -
i trying create archive list blog application. have veiw model has code snippet:
@model ienumerable<nplhblog.models.archivelistmodels> ... @foreach (var item in model) { <li>@item.archivemonth/@item.archiveyear : @item.postcount</li> } ...
i trying print item.archivemonth 'jan' instead of '1'.
the archivelistmodel follows:
public class archivelistmodels { public int archiveyear { get; set; } public int archivemonth { get; set; } public int postcount { get; set; } }
and blogs read repository follows:
public iqueryable<archivelistmodels> archivelist() { var archivelist = blogs in db.blogs group blogs new { blogs.publishdate.year, blogs.publishdate.month } dategroup select new archivelistmodels() { archiveyear = dategroup.key.year, archivemonth = dategroup.key.month, postcount = dategroup.count() }; return archivelist; }
many thanks.
to full month name
int month = 1; system.globalization.cultureinfo.currentuiculture.datetimeformat.getmonthname(month);
or can use datetime string format:
int month = 1; var dt = new datetime(2012, month, 1): var monthabbr = dt.tostring("mmm");
or can lookup against abbreviations list
int month = 1; var monthabbr = system.globalization.cultureinfo.currentuiculture.datetimeformat.abbreviatedmonthnames[month];
Comments
Post a Comment