C#把秒数转换为时分秒格式
小编又遇到时间换算了,小编对此的宗旨就是能百度的到的,就绝不自己花时间研究~private string sec_to_hms(long duration){TimeSpan ts = new TimeSpan(0, 0, Convert.ToInt32(duration));string str = "";if (ts.Hours > 0){str = String.Format("{0:
·
小编又遇到时间换算了,小编对此的宗旨就是能百度的到的,就绝不自己花时间研究~
private string sec_to_hms(long duration)
{
TimeSpan ts = new TimeSpan(0, 0, Convert.ToInt32(duration));
string str = "";
if (ts.Hours > 0)
{
str = String.Format("{0:00}", ts.Hours) + ":" + String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds);
}
if (ts.Hours == 0 && ts.Minutes > 0)
{
str = "00:" + String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds);
}
if (ts.Hours == 0 && ts.Minutes == 0)
{
str = "00:00:" + String.Format("{0:00}", ts.Seconds);
}
return str;
}
更多推荐
已为社区贡献3条内容
所有评论(0)