C # Shows this week

xiaoxiao2021-04-09  365

///

/// Calculate this week start date (Date of the week) /// /// Any day in this week // / Return to the date of the week, the following specific time, minute, second and incoming value " public static datetime calculatefirstdateofweek (datetime somedate) {Int i = somedate.dayofweek - dayofweek.monday; if (i = = -1) i = 6; // I value> = 0, because enumeration reasons, Sunday is in the forehead, and Sunday-Monday = -1 at this time must 7 = 6. TimeSpan TS = New Timespan (i, 0, 0, 0); return somedate.subtract (TS);}

///

/// Calculate this week end date (Date of Worke Day) /// /// Arbitrary day //// Return the date of Worke, after the specific time, division, second and incoming value of public static datetime calculateLastDateOfweek (datetime somedate) {Int i = somedate.dayofweek - dayofweek.sunday; if (i! = 0) i = 7 - i; // Because the enumeration cause, the sunday is ranked at the forefront, and the phase reduction interval is reduced by 7. Timespan TS = New TimeSpan (i, 0, 0, 0); return somedate.add (ts);

///

/// Decisive the date of the selection is this week (which is determined by the current time of the system) /// /// /// public static bool IsThisWeek (DateTime someDate) {// get the corresponding someDate Monday DateTime someMon = CalculateFirstDateOfWeek (someDate); // get Monday DateTime nowMon = CalculateFirstDateOfWeek (DateTime .Now;

Timespan TS = Somemon - NOWMON; if (ts.days <0) TS = -TS; // Positive IF (ts.days> = 7) {Return False;} else {return true;}}

转载请注明原文地址:https://www.9cbs.com/read-133186.html

New Post(0)