Convertir les heures décimales en JJ: HH: MM

Im essayant de convertir un decmial nombre d'heures, de jours, d'heures et de minutes.

C'est ce que j'ai jusqu'à présent, ce n'est pas tout à fait encore là. J'ai besoin de soustraire le nombre d'heures des jours des heures de la partie si cela a du sens?

        ///<summary>
        ///Converts from a decimal value to DD:HH:MM
        ///</summary>
        ///<param name="dHours">The total number of hours</param>
        ///<returns>DD:HH:MM string</returns>
        public static string ConvertFromDecimalToDDHHMM(decimal dHours)
        {
            try
            {
                decimal hours = Math.Floor(dHours); //take integral part
                decimal minutes = (dHours - hours) * 60.0M; //multiply fractional part with 60
                int D = (int)Math.Floor(dHours / 24);
                int H = (int)Math.Floor(hours);
                int M = (int)Math.Floor(minutes);
                //int S = (int)Math.Floor(seconds);   //add if you want seconds
                string timeFormat = String.Format("{0:00}:{1:00}:{2:00}", D, H, M);

                return timeFormat;
            }
            catch (Exception)
            {
                throw;
            }
        }

SOLUTION:

    ///<summary>
    ///Converts from a decimal value to DD:HH:MM
    ///</summary>
    ///<param name="dHours">The total number of hours</param>
    ///<returns>DD:HH:MM string</returns>
    public static string ConvertFromDecimalToDDHHMM(decimal dHours)
    {
        try
        {
            decimal hours = Math.Floor(dHours); //take integral part
            decimal minutes = (dHours - hours) * 60.0M; //multiply fractional part with 60
            int D = (int)Math.Floor(dHours / 24);
            int H = (int)Math.Floor(hours - (D * 24));
            int M = (int)Math.Floor(minutes);
            //int S = (int)Math.Floor(seconds);   //add if you want seconds
            string timeFormat = String.Format("{0:00}:{1:00}:{2:00}", D, H, M);

            return timeFormat;
        }
        catch (Exception)
        {
            throw;
        }
    }

source d'informationauteur WraithNath | 2012-03-14