时间间隔显示

2015-12-11 16:07:40  访问(1370) 赞(0) 踩(0)


        /// <summary>
        /// 时间间隔显示
        /// </summary>
        /// <param name="theValue"></param>
        /// <returns></returns>
        public string TimeIntervalShow(double theValue)
        {
            if(theValue<=0)
                return "0秒";

            if (theValue > (60 * 5))
            {
                return "5分钟以上";
            }

            if(theValue < 60)
            {
                return theValue.ToString() + "秒";
            }

            int intValue = (int)theValue;

            int one = intValue / 60;
            int two = intValue % 60;

            if (one == 0)
                return two.ToString() + "秒";

            return one.ToString() + "分" + two.ToString() + "秒";            
        }


        /// <summary>
        /// 时间间隔显示
        /// </summary>
        /// <param name="theValue"></param>
        /// <returns></returns>
        public string TimeIntervalToFullShow(double theValue)
        {
            if (theValue <= 0)
                return "0秒";

            long longValue = (long)theValue;

            long subValue = (24 * 60 * 60);

            long dV = longValue / subValue;

            longValue = longValue % subValue;

            long hV = longValue / 3600;

            longValue = longValue % 3600;

            long mV = longValue / 60;

            long sV = longValue % 60;


            return TimeIntervalToFullShow8Params
                (
                    dV,
                    hV,
                    mV,
                    sV
                );

        }

        /// <summary>
        /// 打印时间间隔显示
        /// </summary>
        /// <param name="dV"></param>
        /// <param name="hV"></param>
        /// <param name="mV"></param>
        /// <param name="sV"></param>
        /// <returns></returns>
        public string TimeIntervalToFullShow8Params
            (
                long dV,
                long hV,
                long mV,
                long sV                 
            )
        {
            StringBuilder theResult = new StringBuilder();

            bool isShow = false;

            if (dV != 0)
            {
                theResult.Append(dV.ToString() + "天");
                isShow = true;
            }

            if (isShow || hV != 0)
            {
                theResult.Append(hV.ToString() + "小时");
                isShow = true;
            }


            if (isShow || mV != 0)
            {
                theResult.Append(mV.ToString() + "分");
                isShow = true;
            }


            theResult.Append(sV.ToString() + "秒");

            return theResult.ToString();

        }


标签:时间间隔显示 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)