fork download
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. public class Test
  7. {
  8. public static DateTime GetEndOfMonth(DateTime start, bool workingDaysOnly)
  9. {
  10. int year = start.Year;
  11. int month = start.Month;
  12. int daysInMonth = CultureInfo.CurrentCulture.DateTimeFormat.Calendar.GetDaysInMonth(year, month);
  13. var dt = new DateTime(year, month, daysInMonth);
  14. if (workingDaysOnly)
  15. {
  16. switch (dt.DayOfWeek)
  17. {
  18. case DayOfWeek.Saturday:
  19. dt = dt.AddDays(-1);
  20. break;
  21. case DayOfWeek.Sunday:
  22. dt = dt.AddDays(-2);
  23. break;
  24. default:
  25. break;
  26. }
  27. }
  28. return dt;
  29. }
  30.  
  31. public static void Main()
  32. {
  33. DateTime endOfMonth = GetEndOfMonth(DateTime.Today, true);
  34. Console.WriteLine(endOfMonth.ToString("d"));
  35. }
  36. }
Success #stdin #stdout 0.04s 33888KB
stdin
Standard input is empty
stdout
11/29/2013