What is the proper way to get the complete name of month of a DateTime object?
e.g. January, December.
I am currently using:
DateTime.Now.ToString("MMMMMMMMMMMMM");
I know it's not the correct way to do it.
What is the proper way to get the complete name of month of a DateTime object?
e.g. January, December.
I am currently using:
DateTime.Now.ToString("MMMMMMMMMMMMM");
I know it's not the correct way to do it.
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
You can use the CultureInfo from System.Globalization to get that data, based on the current culture that is being used.
_ = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Month)
Or, use InvariantCulture to also get the English name.
_ = CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(DateTime.Now.Month);