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

learning8899 2012-04-09 10:01:25
查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.
...全文
849 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱蹄子的羊头 2012-04-12
  • 打赏
  • 举报
回复
系统是 16ms 处理一次吧。

16ms 里面重复概率还是很高的。你这样不可取
弘石 2012-04-12
  • 打赏
  • 举报
回复
如果只取后9位的话,是从小时开始的,也很有可能重复
如果你为了获取一个唯一的串,不应该这样做
shuaialang 2012-04-11
  • 打赏
  • 举报
回复
你用时间戳的地方难道没有随机数的么。。
弘石 2012-04-11
  • 打赏
  • 举报
回复
从逻辑上说有可能 重复,你设置一个同步锁,这样就不会生成同样的时间戳了
learning8899 2012-04-10
  • 打赏
  • 举报
回复
谢谢大铁锤。使用MilliSecondsBetween真是画龙点睛,非常高明,我没有想到。
毫秒级的时间戳,上百人的话,重复的概率应该是非常罕见的。
这个是返回int64型,如果截取最后9位转换成integer型,应该不会重复吧?
弘石 2012-04-10
  • 打赏
  • 举报
回复
上面的不对,小时应该是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;
弘石 2012-04-10
  • 打赏
  • 举报
回复 1

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

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧