C#秒转换小时

 #region 秒转换小时 SecondToHour
        /// <summary>
        /// 秒转换小时
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static string SecondToHour(double time)
        {
            string str = "";
            int hour = 0;
            int minute = 0;
            int second = 0;
            second = Convert.ToInt32(time);

            if (second > 60)
            {
                minute = second / 60;
                second = second % 60;
            }
            if (minute > 60)
            {
                hour = minute / 60;
                minute = minute % 60;
            }
            return (hour + "小时" + minute + "分钟"
                + second + "");
        } 
        #endregion

比如:一个小时=60分=3600秒

调用:SecondToHour(3600);

显示:

1小时0分钟0秒

 

 

可以再进行优化,如果分钟和秒为0时,就不显示。

http://blog.csdn.net/lilinoscar/article/details/51968565

posted on 2017-03-29 10:31  扶强  阅读(3156)  评论(0编辑  收藏  举报