How to get the integer value of day of week

前端 未结 9 661
太阳男子
太阳男子 2020-12-02 18:15

How do I get the day of a week in integer format? I know ToString will return only a string.

DateTime ClockInfoFromSystem = DateTime.Now;
int day1;
string d         


        
相关标签:
9条回答
  • 2020-12-02 18:44
    DateTime currentDateTime = DateTime.Now;
    int week = (int) currentDateTime.DayOfWeek;
    
    0 讨论(0)
  • 2020-12-02 18:45
    day1= (int)ClockInfoFromSystem.DayOfWeek;
    
    0 讨论(0)
  • 2020-12-02 18:46

    If you want to set first day of the week to Monday with integer value 1 and Sunday with integer value 7

    int day = ((int)DateTime.Now.DayOfWeek == 0) ? 7 : (int)DateTime.Now.DayOfWeek;
    
    0 讨论(0)
提交回复
热议问题