Reputation: 105
I am parsing some dates to be the MMM-dd-yyyy format, but for some reason my month names are coming out in non-standard english names.
May is Mai, October is Okt, March is Mrz , December Dez , why are these not May, Oct, Mar and Dec?
Where am I going wrong?
DateTime projectStartDay = DateTime.Parse("1/1/2017",CultureInfo.CreateSpecificCulture("en-US"));
DateTime projectEndDay = DateTime.Parse("12/1/2017",CultureInfo.CreateSpecificCulture("en-US"));
Console.WriteLine(projectStartDay.ToString("MMM-dd-yyyy"));
Console.WriteLine(projectEndDay.ToString("MMM-dd-yyyy"));
I get the following:
Jan-01-2017
Dez-01-2017 ← I would like that to be Dec-01-2017
Upvotes: 0
Views: 4350
Reputation: 2305
You need to specify the culture when you print it out.
// Creates a CultureInfo for en-US.
CultureInfo ci = new CultureInfo("en-US");
string format = "MMM-dd-yyyy";
Console.WriteLine(projectStartDay.ToString(format, ci));
Console.WriteLine(projectEndDay.ToString(format, ci));
Upvotes: 4