C# 秒数转日期_由秒数得到日期几天几小时

  ///<summary>
        ///由秒数得到日期几天几小时。。。
        ///</summary
        ///<param name="t">秒数</param>
        ///<param name="type">0:转换后带秒,1:转换后不带秒</param>
        ///<returns>几天几小时几分几秒</returns>
        public static string parseTimeSeconds(int t, int type)
        {
            string r = "";
            int day, hour, minute, second;
            if (t >= 86400) //天,
            {
                day = Convert.ToInt16(t / 86400);
                hour = Convert.ToInt16((t % 86400) / 3600);
                minute = Convert.ToInt16((t % 86400 % 3600) / 60);
                second = Convert.ToInt16(t % 86400 % 3600 % 60);
                if (type == 0)
                    r = day + ("") + hour + ("小时") + minute + ("") + second + ("");
                else
                    r = day + ("") + hour + ("小时") + minute + ("");

            }
            else if (t >= 3600)//时,
            {
                hour = Convert.ToInt16(t / 3600);
                minute = Convert.ToInt16((t % 3600) / 60);
                second = Convert.ToInt16(t % 3600 % 60);
                if (type == 0)
                    r = hour + ("小时") + minute + ("") + second + ("");
                else
                    r = hour + ("小时") + minute + ("");
            }
            else if (t >= 60)//
            {
                minute = Convert.ToInt16(t / 60);
                second = Convert.ToInt16(t % 60);
                r = minute + ("") + second + ("");
            }
            else
            {
                second = Convert.ToInt16(t);
                r = second + ("");
            }
            return r;
        }

好用

posted @ 2020-11-27 11:01  net开发人员  阅读(604)  评论(0编辑  收藏  举报