DataTimeHelper.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ShwasherSys
  7. {
  8. public static class DataTimeHelper
  9. {
  10. public static int GetTimeSpanMinute(this DateTime start, DateTime end)
  11. {
  12. return Convert.ToInt32(GetTimeSpan(start, end).TotalMinutes);
  13. }
  14. public static TimeSpan GetTimeSpan(this DateTime start, DateTime end)
  15. {
  16. TimeSpan timeSpan = end - start;
  17. return timeSpan;
  18. }
  19. /// <summary>
  20. /// 字符串转换成日期格式
  21. /// </summary>
  22. /// <param name="pcStr"></param>
  23. /// <returns></returns>
  24. public static DateTime StrToDt(string pcStr)
  25. {
  26. DateTime time1 = new DateTime(1900, 1, 1);
  27. try
  28. {
  29. return DateTime.Parse(pcStr);
  30. }
  31. catch (Exception)
  32. {
  33. // ignored
  34. }
  35. return new DateTime(1900, 1, 1);
  36. }
  37. }
  38. }