原创

c# 将秒时长转换成时分秒显示

需求如下:
file
具体代码:

public static string formatDateTime(string secondTime)
        {
            if (string.IsNullOrEmpty(secondTime))
            {
                return "";
            }
            else
            {
                long mss = long.Parse(secondTime);

                string DateTimes = null;
                long days = mss / (60 * 60 * 24);
                long hours = (mss % (60 * 60 * 24)) / (60 * 60);
                long minutes = (mss % (60 * 60)) / 60;
                long seconds = mss % 60;
                if (days > 0)
                {
                    DateTimes = days + "天" + hours + "小时" + minutes + "分钟"
                     + seconds + "秒";
                }
                else if (hours > 0)
                {
                    DateTimes = hours + "小时" + minutes + "分钟"
                     + seconds + "秒";
                }
                else if (minutes > 0)
                {
                    DateTimes = minutes + "分钟"
                     + seconds + "秒";
                }
                else
                {
                    DateTimes = seconds + "秒";
                }

                return DateTimes;
            }

        }

将时分秒显示成秒的连接
http://www.sigechuizi.cn/article/137

正文到此结束
本文目录