I cant figure how to get the yesterday string to swedish culture
DateTime dateTime = DateTime.Now;
string today = dateTime.DayOfWeek.ToString();
string yesterday = dateTime.AddDays(-1).DayOfWeek.ToString(); //Fetch day i.e. Mon, Tues
I have got culture working for todays day, but not yesterday
var culture = new System.Globalization.CultureInfo("sv-SE");
var day = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek);
Hope someone can help me
CodePudding user response:
You want to use either the ddd
or dddd
custom format specifier with the ToString(string, IFormatProvider)
method.
DateTime dateTime = DateTime.Now;
var culture = new System.Globalization.CultureInfo("sv-SE");
string today = dateTime.ToString("ddd", culture);
string yesterday = dateTime.AddDays(-1).ToString("ddd", culture);