public static DateTime DoubleToDateTime(double xd)

 

          {

 

              int d, h, m, s, mm;

 

              double dd, dh, dm, ds, dmm;

 

              dd = xd;

 

              d = (int)dd;

 

              dh = (dd - d) * 24;

 

              h = (int)dh;

 

              dm = (dh - h) * 60;

 

              m = (int)dm;

 

              ds = (dm - m) * 60;

 

              s = (int)ds;

 

              dmm = (ds - s) * 1000;

 

              mm = (int)dmm;

 

              TimeSpan ts = new TimeSpan(d, h, m, s, mm);

 

              return new DateTime(1899, 12, 30) + ts;

 

          }

 
 
 
 
 
 
 

          unsafe static void Main(string[] args)

 

          {

 

              double d = 41070.979715;

 
 
 
 

              Console.WriteLine(DoubleToDateTime(d));

 

          }

 
 
 
 

  // 和Delphi实际相差1分钟

 
        public static DateTime DoubleToDateTime(double xd)
 
 
        {
 
 
            return (new DateTime(1899, 12, 30)).AddDays(xd);
 
 
        }
 
 
 
  
 
 

           public static double DateTimeToDouble(DateTime dt)
 
 
 

           {
 
 
 

               TimeSpan ts = dt - new DateTime(1899, 12, 30);
 
 
 

               return ts.TotalDays;
 
 
 

           }
 
 
 
 
  
 
 

           public static int GetDayCount(Double MaxDate, DateTime MinDate)
 
 
 

           {
 
 
 

               int result;
 
 
 

               double Day = ((DateTime)DoubleToDateTime(MaxDate) - MinDate).TotalDays;
 
 
 

               if (Day > 0)
 
 
 

               {
 
 
 

                   result = (int)Math.Ceiling(Day);
 
 
 

               }
 
 
 

               else
 
 
 

               {
 
 
 

                   result = 0;
 
 
 

               }
 
 
 

               return result;
 
 
 

           }