How to get from an integer day value day as string

╄→гoц情女王★ 提交于 2020-01-06 16:00:13

问题


I stored into my database as integer day values. From a string array I was getting the day as string.

public static string[] _dayofweek = new string[] {"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"}; 

However, now I want to get the name of day relatively to cultureinfo not only as fixed in english.

Is it possible to get the names of week from this stored day number ?


回答1:


The easiest way is to use ToString("dddd") on a DateTime. I would pick an arbitrary Sunday and use AddDays to translate your index.

int _dayOfWeek = 1; //Monday
string weekdayString = new DateTime(2015, 4, 12).AddDays(_dayOfWeek)
                                                .ToString("dddd");
                     // ^ "Monday" or whatever locale you are in


来源:https://stackoverflow.com/questions/29502210/how-to-get-from-an-integer-day-value-day-as-string

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