Often we get month as integer from external source and want to display it as "Oct" or "October" i.e. string. Following is a code to convert the int month to string month :)
Hope this helps :)
/// <summary>
/// Converts the given month int to month name
/// </summary>
/// <param name="month">month int </param>
/// <param name="abbrev">return abbreviated or not</param>
/// <returns>Short or long month name as string </returns>
private static string GetMonthName(int month, bool abbrev)
{
DateTime date = new DateTime(2000, month, 1);
if (abbrev) return date.ToString("MMM");
return date.ToString("MMMM");
}
4 comments:
Hi Sandeep,
Another culture-specific way is:
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month);
where month is an integral value. You can also substitute CurrentCulture for any other CultureInfo object you like!
Thanks for your comment..
Thats great info Nic..
-Sandeep
Thanks! Just what I was looking for!
no working this code thank you
Post a Comment