Get the Day of a week from integer value of the Day

为君一笑 提交于 2019-12-03 22:14:54

try below code :-

Response.Write(Enum.GetName(typeof(DayOfWeek),5));

Output:

Friday

and If you have to convert integers to days of week, see following sample to convert “2,4,5″ using LINQ.

var t = string.Join(",",
                 from g in "2,4,5".Split(new char[] { ',' })
                 select Enum.GetName(typeof(DayOfWeek), Convert.ToInt32(g)));
        Response.Write(t);

Output:

Tuesday,Thursday,Friday

For extra informations :-

http://msdn.microsoft.com/en-us/library/system.enum.getname(v=vs.110).aspx

Try

CultureInfo.CurrentCulture.DateTimeFormat.DayNames[day No]
Enum.Parse(typeof(DayOfWeek),"0")

where "0" is string equivalent of integer value of day of the week

Adding my answer in case it's any use to anyone:

((DayOfWeek)i).ToString();

Gives 0 = Sunday, 1 = Monday etc

For 0 = Monday just shift along 1

((DayOfWeek)((i + 1) % 7)).ToString();
Chandra

In DateTime.Now DayOfWeek is an enum value and you can get its string value by parsing it to corresponding values.

Enum.Parse(typeof(DayofWeek),"0")

You will get your desired result then.

string.Format("{0:dddd}", value)

Using enumeration doesn't factor in localisation. This string format should return the full day name as a string localised to local culture.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!