C++'s DateTime.Now.Ticks.ToString() Equivalent in delphi?

DateTime.Now.Ticks.ToString() in C++ what is the equivalent in delphi? The strings generated seem very different because I don't think GetTickCount() is the same.. thanks

string hash_id = Utilities.GetMd5Hash(DateTime.Now.Ticks.ToString());
hash_id = hash_id.Substring(0,8)  + "-" + hash_id.Substring(8, 4) + "-" + hash_id.Substring(12, 4) + "-" + hash_id.Substring(16, 4) + "-" + hash_id.Substring(20, 12);

Open in new window


my code:
function sessionhash:string;
var
h,b:string;
begin
h := lowercase(md5string(DateToStr(GetTickCount())));
b := copy(h,0,8)+'-'+copy(h,8,4)+'-'+copy(h,12,4)+'-'+copy(h,16,4)+'-'+copy(h,20,12);
result := b;
end;

Open in new window

nickdelphi777Asked:
Who is Participating?
 
jimyXCommented:
As per the MSDN you get the Difference from 1-Jan-0001 12:00:00 midnight, and not the CPU TickCount.

The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 (0:00:00 UTC on January 1, 0001, in the Gregorian calendar), which represents DateTime.MinValue. It does not include the number of ticks that are attributable to leap seconds.

If I understood the MSDN correctly, the following code is the equivalent of "DateTime.Now.Ticks":
uses DateUtils;

function sessionhash:string;
var
  dt:TDateTime;
  h, b, tick_str:string;
begin
  dt:= EncodeDate(1,1,1);  //1-Jan-0001
  dt:= EncodeTime(0,0,0,0); //12:00:00 midnight
  tick_str:= inttostr(round((MilliSecondsBetween(now,dt) * 1000000) / 100));  //100-nanosecond intervals that have elapsed, 1 m.s. = 1000000 n.s.
  h := lowercase(md5string(tick_str));
  b := copy(h,0,8)+'-'+copy(h,8,4)+'-'+copy(h,12,4)+'-'+copy(h,16,4)+'-'+copy(h,20,12);
  result := b;
end;

Open in new window

0
 
Sinisa VukCommented:
Think that Environment.TickCount is equal to Delphi's GetTickCount (32 bit)
system.environment.tickcount
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.