SecondsToHourMinConverter.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.ToString() is string stringValue)
  20. {
  21. if (double.TryParse(stringValue, out double totalSeconds))
  22. {
  23. var secondAll = Math.Round(totalSeconds, 1, MidpointRounding.AwayFromZero);
  24. // 将总秒数转换为时间跨度
  25. TimeSpan timeSpan = TimeSpan.FromSeconds(secondAll);
  26. // 格式化为 HH:mm:ss
  27. string formattedTime = $"{timeSpan.Hours:D2}:{timeSpan.Minutes:D2}:{timeSpan.Seconds:D2}.{timeSpan.Milliseconds / 10:D2}";
  28. return formattedTime;
  29. }
  30. }
  31. return value;
  32. }
  33. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  34. {
  35. throw new NotImplementedException();
  36. }
  37. }
  38. }