Epoch time + msecs
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Nov 13 10:27:42 PST 2015
On 11/13/15 1:00 PM, Handyman wrote:
> How to get current time as a float (or a double or a real) as a Unix
> epoch + milliseconds (e.g, 1447437383.465, or even 1447437383.46512 with
> finer resolution)? I read http://dlang.org/intro-to-datetime.html and
> the docs of course. I came this far
>
> auto ct = Clock.currTime();
> auto milliseconds = ct.fracSec.msecs;
> auto epoch = ct.toUnixTime();
The toUnixTime call is going to truncate all the subseconds off.
What I would do is this:
auto t = (Clock.currTime() - SysTime.fromUnixTime(0)).total!"msecs" / 1000.0
Which is essentially what toUnixTime would do (but the fromUnixTime(0)
is a constant internally).
-Steve
More information about the Digitalmars-d-learn
mailing list