DateTimeTool.cs 2.2 KB

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