转换为1天:12:00:00形式
public static string GetHoursString(int time, bool showZero = false, bool IsShowEmpty = false)
{
if (showZero)
{
time = time >= 0 ? time : 0;
}
if (IsShowEmpty && time == 0) {
return string.Empty;
}
TimeSpan ts = new TimeSpan(0, 0, time);
StringBuilder sb = new StringBuilder();
int position = 0;
int hours = 0;
if (ts.Days > 0)
{
sb.Append(String.Format("{0}", ts.Days)).Append(LocalizationMgr.GetInstance().GetTextForKey("Timer.Day")).Append(" ");
}
sb.Append(String.Format("{0:D2}", ts.Hours)).Append(":");
sb.Append(String.Format("{0:D2}", ts.Minutes)).Append(":");
sb.Append(String.Format("{0:D2}", ts.Seconds));
return sb.ToString();
}
转换为1d:1h:1m:1s的形式
public static string GetTimeString(int time, int count = -100)
{
TimeSpan ts = new TimeSpan(0, 0, time);
StringBuilder sb = new StringBuilder();
if (ts.Days > 0)
{
sb.Append(ts.Days).Append("d");
count++;
}
if (ts.Hours > 0)
{
sb.Append(ts.Hours).Append("h");
count++;
}
if (ts.Minutes > 0 && count < 2)
{
sb.Append(ts.Minutes).Append("m");
count++;
}
if (ts.Seconds > 0 && count < 2)
{
sb.Append(ts.Seconds).Append("s");
}
return sb.ToString();
}