How to get complete month name from DateTime

后端 未结 9 1497
慢半拍i
慢半拍i 2020-12-07 23:58

What is the proper way to get the complete name of month of a DateTime object?
e.g. January, December.

I am currently usi

相关标签:
9条回答
  • 2020-12-08 00:22
    DateTime birthDate = new DateTime(1981, 8, 9);
    Console.WriteLine ("I was born on the {0}. of {1}, {2}.", birthDate.Day, birthDate.ToString("MMMM"), birthDate.Year);
    
    /* The above code will say:
    "I was born on the 9. of august, 1981."
    
    "dd" converts to the day (01 thru 31).
    "ffffd" converts to 3-letter name of day (e.g. mon).
    "ffffdd" converts to full name of day (e.g. monday).
    "MMM" converts to 3-letter name of month (e.g. aug).
    "MMMM" converts to full name of month (e.g. august).
    "yyyy" converts to year.
    */
    
    0 讨论(0)
  • 2020-12-08 00:23

    Use the "MMMM" custom format specifier:

    DateTime.Now.ToString("MMMM");
    
    0 讨论(0)
  • 2020-12-08 00:35

    It's

    DateTime.Now.ToString("MMMM");
    

    With 4 Ms.

    0 讨论(0)
提交回复
热议问题