小编又遇到时间换算了,小编对此的宗旨就是能百度的到的,就绝不自己花时间研究~

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;
}

转载文章出自阳光梦想的博客——【代码】C#把秒数转换为时分秒格式

在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐