Convert month int to month name

后端 未结 4 429
孤街浪徒
孤街浪徒 2020-12-07 21:38

I was simply trying to use the DateTime structure to transform an integer between 1 and 12 into an abbrieviated month name.

Here is what I tried:

<
相关标签:
4条回答
  • 2020-12-07 22:11
    var monthIndex = 1;
    return month = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(monthIndex);
    

    You can try this one as well

    0 讨论(0)
  • 2020-12-07 22:22
    CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
    

    See Here for more details.

    Or

    DateTime dt = DateTime.Now;
    Console.WriteLine( dt.ToString( "MMMM" ) );
    

    Or if you want to get the culture-specific abbreviated name.

    GetAbbreviatedMonthName(1);
    

    Reference

    0 讨论(0)
  • 2020-12-07 22:25
    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");
    
    0 讨论(0)
  • 2020-12-07 22:33

    You can do something like this instead.

    return new DateTime(2010, Month, 1).ToString("MMM");
    
    0 讨论(0)
提交回复
热议问题