您的位置:首页 > 编程语言 > C#

C# 根据一个数区分小时,分钟,秒

2016-08-22 09:47 176 查看
根据一个数区分小时,分钟,秒

/// <summary>
/// 根据一个数,区分小时,分钟,秒
/// </summary>
/// <returns></returns>
public string GetTimeString()
{
string time = "";
try
{

TimeSpan ts = new TimeSpan(0, 0, recordCount); //recordCount 就是那个数

if (ts.Hours.ToString().Length < 2)
{
time += "0" + ts.Hours + ":";
}
else
{
time += ts.Hours + ":";
}

if (ts.Minutes.ToString().Length < 2)
{
time += "0" + ts.Minutes + ":";
}
else
{
time += ts.Minutes + ":";
}

if (ts.Seconds.ToString().Length < 2)
{
time += "0" + ts.Seconds;
}
else
{
time += ts.Seconds;
}

}
catch(Exception ex)
{
MedicalLog.InsertSystemLog("VideoRecordItem.cs", "GetTimeString", ex);
}

return time;
}


返回的格式是: 00:00:00
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐