获取DateTime对象的完整月份名称的正确方法是什么? 1月,12月。
我目前使用:
DateTime.Now.ToString("MMMMMMMMMMMMM");
我知道这不是正确的做法。
获取DateTime对象的完整月份名称的正确方法是什么? 1月,12月。
我目前使用:
DateTime.Now.ToString("MMMMMMMMMMMMM");
我知道这不是正确的做法。
当前回答
它应该是DateTime。ToString("MMMM")
你不需要所有额外的Ms。
其他回答
你可以使用文化来获取你国家的月份名称,比如:
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("ar-EG");
string FormatDate = DateTime.Now.ToString("dddd., MMM dd yyyy, hh:MM tt", culture);
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).
"ddd" converts to 3-letter name of day (e.g. mon).
"dddd" 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.
*/
如果你需要三个月的信件,请使用“MMM”
Debug.writeline(Format(Now, "dd MMMM yyyy"))
(DateTime = {07/01/2023 12:00:00 AM})
DateTime.ToString("MMMM") - ( January )