时间与小数的转换


    ///


    ///  Time and Decimal Conversion
    ///

    public class TimeDecimalConversion
    {
        ///
        /// Convert Time to Decimal
        ///

        ///
        ///
        public static decimal ConvertToDecimal(DateTime time)
        {
            decimal result = time.Hour + time.Minute / 60.00M;
            return decimal.Round(result, 2);
        }
        ///
        /// Convert decimal to time
        ///

        ///
        ///
        public static DateTime ConvertToTime(decimal timeDecimal)
        {

            int hour = (int)timeDecimal % 24;
            int minute = (int)Math.Round(timeDecimal * 100 % 100 * 60 / 100);
            return new DateTime(DateTime.MinValue.Year, DateTime.MinValue.Month, DateTime.MinValue.Day, hour, minute, 00);
        }
    }

你可能感兴趣的:(.NET,&,C#)