Getting a short day name

♀尐吖头ヾ 提交于 2019-12-03 22:36:35

You can use DateTimeFormatInfo.AbbreviatedDayNames. For example:

string[] names = culture.DateTimeFormat.AbbreviatedDayNames;
string monday = names[(int) DayOfWeek.Monday];

The closest you can get is use a custom date and time format string - specifically ddd.

This will return an abbreviation - you can substring the result to get to 2 characters.

You will need to use a DateTime with a day corresponding to the day of week you wish.

DateTimeFormatInfo.ShortestDayNames

Gets or sets a string array of the shortest unique abbreviated day names associated with the current DateTimeFormatInfo object.

You can use "ddd" in in a custom format string to get the short day name. For example.

DateTime.Now.ToString("ddd");

As suggestby @Loudenvier in comments.

try:

CultureInfo english = new CultureInfo("en-US");
string sunday = (english.DateTimeFormat.DayNames[(int)DayOfWeek.Sunday]).Substring(0, 2);

Or:

dateTimeFormats = new CultureInfo("en-US").DateTimeFormat;
string sunday = (dateValue.ToString("dddd", dateTimeFormats)).Substring(0, 2);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!