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

来源:互联网 发布:linux静态服务器 编辑:程序博客网 时间:2024/04/26 08:15



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

        /// <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
















1 0