DateTimeTool.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //************************************************************************
  2. // https://github.com/yuzhengyang
  3. // author: yuzhengyang
  4. // date: 2017.3.29 - 2017.8.17
  5. // desc: 日期时间工具
  6. // Copyright (c) yuzhengyang. All rights reserved.
  7. //************************************************************************
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Text;
  11. namespace Y.Utils.DataUtils.DateTimeUtils
  12. {
  13. public sealed class DateTimeTool
  14. {
  15. public static DateTime TodayDate()
  16. {
  17. DateTime today = DateTime.Now;
  18. DateTime result = new DateTime(today.Year, today.Month, today.Day);
  19. return result;
  20. }
  21. public static DateTime TodayDate(DateTime today)
  22. {
  23. DateTime result = new DateTime(today.Year, today.Month, today.Day);
  24. return result;
  25. }
  26. public static TimeSpan TimeSpan(DateTime dt1, DateTime dt2)
  27. {
  28. if (dt1 > dt2)
  29. return dt1 - dt2;
  30. else
  31. return dt2 - dt1;
  32. }
  33. public static Tuple<int, int> ToMS(double second)
  34. {
  35. int Minute = 0, Second = 0;
  36. Minute = (int)second / 60;
  37. Second = (int)second % 60;
  38. return new Tuple<int, int>(Minute, Second);
  39. }
  40. public static Tuple<long, long, long> ToHMS(long ms)
  41. {
  42. long Hour = ms / 1000 / 60 / 60;
  43. long Minute = ms / 1000 / 60 % 60;
  44. long Second = ms / 1000 % 60;
  45. return new Tuple<long, long, long>(Hour, Minute, Second);
  46. }
  47. public static Tuple<int, int, int> ToHMS(int ms)
  48. {
  49. int Hour = ms / 1000 / 60 / 60;
  50. int Minute = ms / 1000 / 60 % 60;
  51. int Second = ms / 1000 % 60;
  52. return new Tuple<int, int, int>(Hour, Minute, Second);
  53. }
  54. }
  55. }