DateTimeTool.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. public static Tuple<long, long, long> ToHMS(long ms)
  38. {
  39. long Hour = ms / 1000 / 60 / 60;
  40. long Minute = ms / 1000 / 60 % 60;
  41. long Second = ms / 1000 % 60;
  42. return new Tuple<long, long, long>(Hour, Minute, Second);
  43. }
  44. public static Tuple<int, int, int> ToHMS(int ms)
  45. {
  46. int Hour = ms / 1000 / 60 / 60;
  47. int Minute = ms / 1000 / 60 % 60;
  48. int Second = ms / 1000 % 60;
  49. return new Tuple<int, int, int>(Hour, Minute, Second);
  50. }
  51. }
  52. }