How to get complete month name from DateTime

后端 未结 9 1496
慢半拍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:10

    You can use Culture to get month name for your country like:

    System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("ar-EG");
    string FormatDate = DateTime.Now.ToString("ffffdd., MMM dd yyyy, hh:MM tt", culture);
    
    0 讨论(0)
  • 2020-12-08 00:12

    Sharing science is beautiful and in the pleasure of god

    Debug.writeline(Format(Now, "dd MMMM yyyy"))
    
    0 讨论(0)
  • 2020-12-08 00:13

    If you receive "MMMM" as a response, probably you are getting the month and then converting it to a string of defined format.

    DateTime.Now.Month.ToString("MMMM") 
    

    will output "MMMM"

    DateTime.Now.ToString("MMMM") 
    

    will output the month name

    0 讨论(0)
  • 2020-12-08 00:16

    If you want the current month you can use DateTime.Now.ToString("MMMM") to get the full month or DateTime.Now.ToString("MMM") to get an abbreviated month.

    If you have some other date that you want to get the month string for, after it is loaded into a DateTime object, you can use the same functions off of that object:
    dt.ToString("MMMM") to get the full month or dt.ToString("MMM") to get an abbreviated month.

    Reference: Custom Date and Time Format Strings

    Alternatively, if you need culture specific month names, then you could try these: DateTimeFormatInfo.GetAbbreviatedMonthName Method
    DateTimeFormatInfo.GetMonthName Method

    0 讨论(0)
  • 2020-12-08 00:18

    You can do as mservidio suggested, or even better, keep track of your culture using this overload:

    DateTime.Now.ToString("MMMM", CultureInfo.InvariantCulture);
    
    0 讨论(0)
  • 2020-12-08 00:21

    It should be just DateTime.ToString( "MMMM" )

    You don't need all the extra Ms.

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