时间字符串更改
This commit is contained in:
@@ -43,10 +43,22 @@ namespace CapMachine.Wpf.Converts
|
|||||||
//int second = TotalSec % 60;
|
//int second = TotalSec % 60;
|
||||||
|
|
||||||
//return string.Format("{0}:{1}:{2}", hour, minute, second);
|
//return string.Format("{0}:{1}:{2}", hour, minute, second);
|
||||||
////Console.WriteLine(result);
|
//////Console.WriteLine(result);
|
||||||
|
|
||||||
TimeSpan TimeInfo = TimeSpan.FromSeconds(TotalSec);
|
//TimeSpan TimeInfo = TimeSpan.FromSeconds(TotalSec);
|
||||||
return TimeInfo.ToString();
|
//return TimeInfo.ToString();
|
||||||
|
|
||||||
|
return ConvertSecToTimeStr(TotalSec);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ConvertSecToTimeStr(int totalSeconds)
|
||||||
|
{
|
||||||
|
int hours = totalSeconds / 3600;
|
||||||
|
int remainingSeconds = totalSeconds % 3600;
|
||||||
|
int minutes = remainingSeconds / 60;
|
||||||
|
int seconds = remainingSeconds % 60;
|
||||||
|
|
||||||
|
return $"{hours}:{minutes:D2}:{seconds:D2}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -57,8 +69,9 @@ namespace CapMachine.Wpf.Converts
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TimeSpan TimeInfo = TimeSpan.Parse(timeString);
|
//TimeSpan TimeInfo = TimeSpan.Parse(timeString);
|
||||||
return (int)TimeInfo.TotalSeconds;
|
//return (int)TimeInfo.TotalSeconds;
|
||||||
|
return ConvertTimeStrToSecs(timeString);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -68,5 +81,23 @@ namespace CapMachine.Wpf.Converts
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int ConvertTimeStrToSecs(string timeString)
|
||||||
|
{
|
||||||
|
string[] parts = timeString.Split(':');
|
||||||
|
if (parts.Length != 3) return 0;
|
||||||
|
//throw new FormatException("Invalid time format. Use 'hh:mm:ss'");
|
||||||
|
|
||||||
|
if (!int.TryParse(parts[0], out int hours) || hours < 0) return 0;
|
||||||
|
//throw new ArgumentException("小時必須為非負整數");
|
||||||
|
|
||||||
|
if (!int.TryParse(parts[1], out int minutes) || minutes < 0 || minutes >= 60) return 0;
|
||||||
|
//throw new ArgumentException("分鐘必須為 0-59 的整數");
|
||||||
|
|
||||||
|
if (!int.TryParse(parts[2], out int seconds) || seconds < 0 || seconds >= 60) return 0;
|
||||||
|
//throw new ArgumentException("秒必須為 0-59 的整數");
|
||||||
|
|
||||||
|
return hours * 3600 + minutes * 60 + seconds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1134,6 +1134,7 @@ namespace CapMachine.Wpf.Services
|
|||||||
// IsShowCount = 0;
|
// IsShowCount = 0;
|
||||||
// IsValueShow = true;
|
// IsValueShow = true;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
foreach (var itemTag in TagManger.DicTags)
|
foreach (var itemTag in TagManger.DicTags)
|
||||||
{
|
{
|
||||||
//TagManger.GetTagInfoValueByName<short>(itemTag.Value.Name)!.Value = (short)random.Next(0, 100);
|
//TagManger.GetTagInfoValueByName<short>(itemTag.Value.Name)!.Value = (short)random.Next(0, 100);
|
||||||
|
|||||||
@@ -15897,8 +15897,16 @@ namespace CapMachine.Wpf.ViewModels
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TimeSpan TimeInfo = TimeSpan.FromSeconds(TotalSec);
|
//TimeSpan TimeInfo = TimeSpan.FromSeconds(TotalSec);
|
||||||
return TimeInfo.ToString();
|
//return TimeInfo.ToString();
|
||||||
|
|
||||||
|
int hours = TotalSec / 3600;
|
||||||
|
int remainingSeconds = TotalSec % 3600;
|
||||||
|
int minutes = remainingSeconds / 60;
|
||||||
|
int seconds = remainingSeconds % 60;
|
||||||
|
|
||||||
|
return $"{hours}:{minutes:D2}:{seconds:D2}";
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -15908,8 +15916,6 @@ namespace CapMachine.Wpf.ViewModels
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region 公共库
|
#region 公共库
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user