2个datetime的时间差如何转换成float

解决方案 »

  1.   

    直接相减,datetime实际上是double类型
      

  2.   

    TDateTime类型的定义   TDateTime = type Double;取当前时间的函数:
    Date() 日期
    Time() 时间
    Now()  日期+时间
      

  3.   

    借贵贴问一下:有能把标准的字符串:XXXX年XX月XX日XX小时XX分钟XX秒  转换为now()这种类型的函数么?
      

  4.   

    var
     date1,date2: TDateTime;
     f: Float;
    begin
     f := date1-date2;
    end;
      

  5.   

    Delphi中时间差直接相减就可以了
    取得当前系统时间可使用now()函数,如:Edit1.text:=now();
    运行就OK了!
      

  6.   

    上面打漏了,应该是Edit1.text:=DateTimetostr(now());
      

  7.   

    字符串到时间有strtodatetime 和decodedatetime 2个函数可以转换.
      

  8.   

    datetime 类型是double的,他的整数部分是年月日,小数部分是时间。所以要天数差的话直接减整数部分就OK了
      

  9.   

    TDateTime represents a date-and-time value in the Delphi language.UnitSystemDelphi syntax:type TDateTime = type Double;DescriptionMost CLX objects represent date and time values using a TDateTime value. In Delphi, TDateTime is a type that maps to a Double. In C++, the TDateTime class corresponds to the Delphi TDateTime type. The integral part of a Delphi TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of the TDateTime value is fraction of a 24 hour day that has elapsed. Following are some examples of TDateTime values and their corresponding dates and times:0 12/30/1899 12:00 am
    2.75 1/1/1900 6:00 pm
    -1.25 12/29/1899 6:00 am
    35065 1/1/1996 12:00 am
    To find the fractional number of days between two dates, simply subtract the two values, unless one of the TDateTime values is negative. Similarly, to increment a date and time value by a certain fractional number of days, add the fractional number to the date and time value if the TDateTime value is positive. 
    When working with negative TDateTime values, computations must handle time portion separately. The fractional part reflects the fraction of a 24-hour day without regard to the sign of the TDateTime value. For example, 6:00 am on 12/29/1899 is -1.25, not -1 + 0.25, which would be -0.75. There are no TDateTime values between -1 and 0.There are no TDateTime values between -1 and 0.