开发者

int => Weekdayname

Is there some inbuilt function to return weekdayname based开发者_运维技巧 on value 1-7?

/M


System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames

more info


for integers from 1 to 7, you'll need to subtract 1 as the array is zero-indexed.

for(int i = 1; i < 8; i++)
{
    Console.WriteLine(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames[i-1]);
}

This will give localised weekday names based on the current culture.


An even shorter way, it turns out there's a built in enum for this purpose:

Enum.GetName(typeof(DayOfWeek), weekDayNumberHere)

But I wouldn't use it for sites needing globalization


try this

DateTime dateValue = new DateTime(2008, 6, 11);
Console.WriteLine(dateValue.ToString("dddd"));    // Displays Wednesday
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜