日期:2014-05-17  浏览次数:20561 次

如何将时:分:秒 转换成秒?
比如 1小时20分钟30秒 01:20:30 
如何将01:20:30转换成秒?

有没有简单的方法?

------解决方案--------------------
引用:
Quote: 引用:


TimeSpan ts = new TimeSpan(1,20,30);
double seconds = ts.TotalSeconds;


是这样的,我这边的实际的秒数据很大很大,比如有123456789秒
所以我就先用
TimeSpan strTimeSpan = new TimeSpan(0, 0, 0, 123456789);
得出的 时:分:秒 中的小时是XXX.XX
然后用你的那个方法算,就出错,原因就在那个XXX.XX小时,请问到底是怎么回事?



TimeSpan strTimeSpan = new TimeSpan(0, 0, 0, 123456789);
//
        // 摘要:
        //     将新的 System.TimeSpan 初始化为指定的天数、小时数、分钟数和秒数。
        //
        // 参数:
        //   days:
        //     天数。
        //
        //   hours:
        //     小时数。
        //
        //   minutes:
        //     分钟数。
        //
        //   seconds:
        //     秒数。
        //
        // 异常:
        //   System.ArgumentOutOfRangeException:
        //     该参数指定一个小于 System.TimeSpan.MinValue 或大于 System.TimeSpan.MaxValue 的 System.TimeSpan
        //     值。
TimeSpan ts = new TimeSpan(strTimeSpan.Days, strTimeSpan.Hours, strTimeSpan.Minutes, strTimeSpan.Seconds);
double seconds = ts.TotalSeconds;