查help,DateTimeToUnix只能精确到秒,请问各位朋友,有没有精确到毫秒的时间戳函数?Converts a TDateTime value into a Unix/Linux-style date-and-time value.UnitDateUtilsCategorymeasurement conversion routinesDelphi syntax:function DateTimeToUnix(const AValue: TDateTime): Int64;C++ syntax:extern PACKAGE __int64 __fastcall DateTimeToUnix(const System::TDateTime AValue);DescriptionCall DateTimeToUnix to convert a TDateTime value the corresponding Unix/Linux encoding of the same date and time.Unix/Linux date-and-time values are encoded as the number of seconds since midnight at the start of January 1, 1970. 

解决方案 »

  1.   


    function GetJavaTime( d: TDateTime ): Int64;
    var
      dJavaStart: TDateTime;
    begin
      dJavaStart := EncodeDateTime( 1970, 1, 1, 8, 0, 0, 0 );
      Result := MilliSecondsBetween( d, dJavaStart );
    end;
      

  2.   

    上面的不对,小时应该是0
    function GetJavaTime( d: TDateTime ): Int64;
    var
      dJavaStart: TDateTime;
    begin
      //java里的时间是从1970年1月1日0点到当前的间隔
      dJavaStart := EncodeDateTime( 1970, 1, 1, 0, 0, 0, 0 );  
      Result := MilliSecondsBetween( d, dJavaStart );
    end;
      

  3.   

    谢谢大铁锤。使用MilliSecondsBetween真是画龙点睛,非常高明,我没有想到。
    毫秒级的时间戳,上百人的话,重复的概率应该是非常罕见的。
    这个是返回int64型,如果截取最后9位转换成integer型,应该不会重复吧?
      

  4.   

    系统是 16ms 处理一次吧。16ms 里面重复概率还是很高的。你这样不可取