Clock.currTime differs from SysTime

Ivo ivo at asdasdl.com
Sat Aug 25 12:53:24 UTC 2018


I am using Clock.currTime.stdTime to get a unique timestamp in my 
program.
Now I need to produce something similar in a different 
programming language; so I'm trying to understand how 
Clock.currTime works.

According the the documentation Clock.currTime.stdTime should 
return the number of hnseconds since 00:00 of 01/01/0001 A.D. 
UTC. However it seems that it returns less than what claimed.

Consider the following code:

import std.stdio;
import std.datetime.date : DateTime;
import std.datetime.timezone : UTC;
import std.datetime.systime;

void main() {

auto now = Clock.currTime;
auto date = DateTime(2018, 8, 25, 14, 42, 0); //this is changed 
manually
auto st = SysTime(date, UTC());
writeln(st.stdTime);
writeln(st.toISOExtString);
writeln(now.stdTime);
writeln(now.toISOExtString);

}

I'm done a few tries and here is an output:
636708049200000000 //this is st.stdTime
2018-08-25T14:42:00Z
636707977205129550 //this is now.stdTime
2018-08-25T14:42:00.512955

So here is the problem: the difference in time is less than 0.6 
seconds (according to the strings), nevertheless the difference 
of the 2 numbers is 71994870450.
71994870450 hnsecs = 71994870450 x 10^{-7} secs = 7199,487045 
secs (unless my maths is wrong)

So what actually is Clock.currTime.stdTime counting?



More information about the Digitalmars-d-learn mailing list