SecondsToHourMinConverter.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using ExtendedGrid.Microsoft.Windows.Controls;
  2. using SciChart.Core.Extensions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Data;
  11. namespace MECF.Framework.UI.Client.Converter
  12. {
  13. public class SecondsToHourMinConverter : IValueConverter
  14. {
  15. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  16. {
  17. if (value == null)
  18. return "";
  19. if (value is float floatResult)
  20. {
  21. var secondAll = Math.Round(floatResult, 1, MidpointRounding.AwayFromZero);
  22. // 将总秒数转换为时间跨度
  23. TimeSpan timeSpan = TimeSpan.FromSeconds(secondAll);
  24. // 格式化为 HH:mm:ss
  25. string formattedTime = $"{timeSpan.Hours:D2}:{timeSpan.Minutes:D2}:{timeSpan.Seconds:D2}";
  26. return formattedTime;
  27. }
  28. return "";
  29. }
  30. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  31. {
  32. return "";
  33. }
  34. }
  35. }