DateTimeExtensionMethod.cs 782 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace VCommon
  5. {
  6. public static class DateTimeExtensionMethod
  7. {
  8. public static DateTime[] GetBetweenMonths(this DateTime begin, DateTime end)
  9. {
  10. return Enumerable.Range(0, (end.Year - begin.Year) * 12 + (end.Month - begin.Month + 1))
  11. .Select(p => new DateTime(begin.Year, begin.Month, 1).AddMonths(p))
  12. .ToArray();
  13. }
  14. public static DateTime[] GetBetweenDays(this DateTime begin, DateTime end)
  15. {
  16. var allDays = new List<DateTime>();
  17. for (DateTime date = begin; date <= end; date = date.AddDays(1))
  18. allDays.Add(date);
  19. return allDays.ToArray();
  20. }
  21. }
  22. }