读书人

请问:delphi有么有精确到毫秒的时间戳

发布时间: 2012-04-18 15:01:59 作者: rapoo

请教:delphi有么有精确到毫秒的时间戳?
查help,DateTimeToUnix只能精确到秒,请问各位朋友,有没有精确到毫秒的时间戳函数?

Converts a TDateTime value into a Unix/Linux-style date-and-time value.

Unit

DateUtils

Category

measurement conversion routines

Delphi syntax:

function DateTimeToUnix(const AValue: TDateTime): Int64;

C++ syntax:

extern PACKAGE __int64 __fastcall DateTimeToUnix(const System::TDateTime AValue);

Description

Call 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.

[解决办法]

Delphi(Pascal) code
function GetJavaTime( d: TDateTime ): Int64;var  dJavaStart: TDateTime;begin  dJavaStart := EncodeDateTime( 1970, 1, 1, 8, 0, 0, 0 );  Result := MilliSecondsBetween( d, dJavaStart );end;
[解决办法]
上面的不对,小时应该是0
Delphi(Pascal) code
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;
[解决办法]
从逻辑上说有可能 重复,你设置一个同步锁,这样就不会生成同样的时间戳了
[解决办法]
你用时间戳的地方难道没有随机数的么。。
[解决办法]
如果只取后9位的话,是从小时开始的,也很有可能重复
如果你为了获取一个唯一的串,不应该这样做
[解决办法]
系统是 16ms 处理一次吧。

16ms 里面重复概率还是很高的。你这样不可取

读书人网 >.NET

热点推荐