DateTimeHelper.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using NPOI.SS.Formula.Functions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace ProductionLineMonitor.Core.Utils
  6. {
  7. public class DateTimeHelper
  8. {
  9. public static void GetStartEndTime(DateTime date, out DateTime startTime, out DateTime endTime)
  10. {
  11. int year, month, day;
  12. year = date.Year;
  13. month = date.Month;
  14. day = date.Day;
  15. if (day < 21)
  16. {
  17. month -= 1;
  18. if (month == 0)
  19. {
  20. year -= 1;
  21. month = 12;
  22. }
  23. }
  24. startTime = Convert.ToDateTime($"{year}-{month}-21 08:00:00");
  25. endTime = startTime.AddMonths(1).AddDays(-1);
  26. }
  27. public static List<object> GetDate(DateTime startTime, DateTime endTime)
  28. {
  29. List<object> rev = new List<object>();
  30. for (DateTime dt = startTime; dt <= endTime; dt = dt.AddDays(+1))
  31. {
  32. rev.Add(dt.ToString("yyyy-MM-dd"));
  33. }
  34. return rev;
  35. }
  36. public static List<DateTime> GetDateTime(DateTime startTime, DateTime endTime)
  37. {
  38. List<DateTime> rev = new List<DateTime>();
  39. for (DateTime dt = startTime; dt < endTime; dt = dt.AddDays(+1))
  40. {
  41. rev.Add(dt);
  42. }
  43. return rev;
  44. }
  45. public static List<string> GetDateString(DateTime startTime, DateTime endTime)
  46. {
  47. List<string> rev = new List<string>();
  48. for (DateTime dt = startTime; dt <= endTime; dt = dt.AddDays(+1))
  49. {
  50. rev.Add(dt.ToString("yyyy-MM-dd"));
  51. }
  52. return rev;
  53. }
  54. public static List<object> GetDateShift(DateTime startTime, DateTime endTime)
  55. {
  56. List<object> rev = new List<object>();
  57. for (DateTime dt = startTime; dt <= endTime; dt = dt.AddDays(+1))
  58. {
  59. rev.Add(dt.ToString("yyyy-MM-dd 08:00:00"));
  60. rev.Add(dt.ToString("yyyy-MM-dd 20:00:00"));
  61. }
  62. return rev;
  63. }
  64. public static List<object> GetDateShiftV1(DateTime startTime, DateTime endTime)
  65. {
  66. List<object> rev = new List<object>();
  67. for (DateTime dt = startTime; dt <= endTime; dt = dt.AddDays(+1))
  68. {
  69. rev.Add(dt.ToString("yyyy-MM-dd 白班"));
  70. rev.Add(dt.ToString("yyyy-MM-dd 夜班"));
  71. }
  72. return rev;
  73. }
  74. }
  75. }