Example #1
0
        /// <summary>转换成对应的字符串格式(x 天 xx 小时 xx 分 xx 秒 xxx 毫秒)</summary>
        /// <param name="ts">时间间隔</param>
        /// <returns>“x 天 xx 小时 xx 分 xx 秒 xxx 毫秒”格式的字符串</returns>
        public static string ToString_(this TimeSpan ts)
        {
            STR  str = new STR(30);
            bool is0 = true;
            int  temp;

            temp = ts.Days;
            if (temp != 0)
            {
                str.Append(temp).Append(Constants.TimeSpanDays);
                is0 = false;
            }
            temp = ts.Hours;
            if (temp != 0 || !is0)
            {
                str.Append(temp).Append(Constants.TimeSpanHours);
            }
            temp = ts.Minutes;
            if (temp != 0 || !is0)
            {
                str.Append(temp).Append(Constants.TimeSpanMinutes);
            }
            temp = ts.Seconds;
            if (temp != 0 || !is0)
            {
                str.Append(temp).Append(Constants.TimeSpanSeconds);
            }
            temp = ts.Milliseconds;
            if (temp != 0 || is0)
            {
                str.Append(temp).Append(Constants.TimeSpanMilliseconds);
            }

            return(str.TrimEnd().ToString());
        }