DateTimeTool.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //############################################################
  2. // https://github.com/yuzhengyang
  3. // author:yuzhengyang
  4. //############################################################
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text;
  8. namespace Y.Utils.DataUtils.DateTimeUtils
  9. {
  10. public sealed class DateTimeTool
  11. {
  12. public static DateTime TodayDate()
  13. {
  14. DateTime today = DateTime.Now;
  15. DateTime result = new DateTime(today.Year, today.Month, today.Day);
  16. return result;
  17. }
  18. public static DateTime TodayDate(DateTime today)
  19. {
  20. DateTime result = new DateTime(today.Year, today.Month, today.Day);
  21. return result;
  22. }
  23. public static TimeSpan TimeSpan(DateTime dt1, DateTime dt2)
  24. {
  25. if (dt1 > dt2)
  26. return dt1 - dt2;
  27. else
  28. return dt2 - dt1;
  29. }
  30. public static Tuple<int, int> ToMS(double second)
  31. {
  32. int Minute = 0, Second = 0;
  33. Minute = (int)second / 60;
  34. Second = (int)second % 60;
  35. return new Tuple<int, int>(Minute, Second);
  36. }
  37. }
  38. }