秒轉換成時分秒

private String returnFullTimes(int theSecond)
        {
            int h = 0, m = 0, s = 0;

            h = (int)Math.Floor(theSecond / 3600.0);
            if (h > 0)
            {
                m = (int)Math.Floor((theSecond - h * 3600.0) / 60);
                if (m > 0)
                {
                    s = theSecond - h * 3600 - m * 60;
                }
                else
                {
                    s = theSecond - h * 3600;       //原來這裏寫錯了,寫成了s   =   theSecond;   
                }
            }
            else
            {
                m = (int)Math.Floor(theSecond / 60.0);
                if (m > 0)
                {
                    s = theSecond - m * 60;
                }
                else
                {
                    s = theSecond;
                }
            }
            return h + "" + m + "" + s + "";
        }
相關文章
相關標籤/搜索