秒数 | 转换后的时分秒 |
---|
17 | 00:00:17 |
355 | 00:05:55 |
4550 | 01:15:50 |
public static string sec_to_hms(int duration)
{
TimeSpan ts = new TimeSpan(0, 0, duration);
int _hours = 0;
if (ts.Days > 0)
{
_hours = ts.Days * 24;
}
string str = "";
if (ts.Hours > 0)
{
str = String.Format("{0:00}", ts.Hours + _hours) + ":" + String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds);
}
if (ts.Hours == 0 && ts.Minutes > 0)
{
str = "00:";
if (_hours > 0)
{
str = String.Format("{0:00}", ts.Hours + _hours) + ":";
}
str += String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds);
}
if (ts.Hours == 0 && ts.Minutes == 0)
{
str = "00";
if (_hours > 0)
{
str = String.Format("{0:00}", ts.Hours + _hours);
}
str += ":00:" + String.Format("{0:00}", ts.Seconds);
}
return str;
}