c# - Remaining time until weekend is over -
i want calculate how many seconds there left until weekend on (say until sunday 11.59pm). when operation called in weekend needs return timespan. need on weekly basis cant set 'hard-coded' enddate
new datetime(2014, 04, 17, 23, 12, 33);
how set correct enddate calculate remaining seconds now?
try:
public static void main(string[] args) { //your code goes here timespan span = (next(datetime.now, dayofweek.sunday).date + new timespan(23, 59, 00)).subtract(datetime.now); console.writeline(span.totalseconds); } public static datetime next(datetime from, dayofweek dayofweek) { int start = (int) from.dayofweek; int target = (int) dayofweek; if (target <= start) target += 7; return from.adddays(target - start); }
Comments
Post a Comment