如何获得星期几的整数值

如何以整数格式获得一周的哪一天? 我知道ToString将只返回一个string。

DateTime ClockInfoFromSystem = DateTime.Now; int day1; string day2; day1= ClockInfoFromSystem.DayOfWeek.ToString(); /// it is not working day2= ClockInfoFromSystem.DayOfWeek.ToString(); /// it gives me string 

使用

 day1 = (int)ClockInfoFromSystem.DayOfWeek; 
 int day = (int)DateTime.Now.DayOfWeek; 

星期一的第一天:星期天(价值为零)

如果要将星期几的第一天设置为星期一,则整数值为1,星期日为整数值7

 int day = ((int)DateTime.Now.DayOfWeek == 0) ? 7 : (int)DateTime.Now.DayOfWeek; 
 day1= (int)ClockInfoFromSystem.DayOfWeek; 

尝试这个。 它会工作得很好:

 int week = Convert.ToInt32(currentDateTime.DayOfWeek); 

将DayOfWeek等Enum的整数值作为string的正确方法是:

 DayOfWeek.ToString("d") 
 DateTime currentDateTime = DateTime.Now; int week = (int) currentDateTime.DayOfWeek;