How to get current time as long or ulong?
Charles Hixson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 5 12:51:54 PDT 2016
On 07/05/2016 11:43 AM, Jonathan M Davis via Digitalmars-d-learn wrote:
> On Tuesday, July 05, 2016 11:16:31 Charles Hixson via Digitalmars-d-learn
> wrote:
>> What I'm looking for is the opposite of the "FromUnixTime" function.
> SysTime has toUnixTime, which is right above fromUnixTime in the
> documentation.
>
> But if what you want is a time_t, and you don't want to deal with SysTime,
> there's no point in using std.datetime. Just use core.time to call C's time
> function.
>
> - Jonathan M Davis
>
That's what I want, but I'm worried by the documentation saying:
" This has no relation to the wall clock time, as the wall clock time
can be adjusted (e.g. by NTP), whereas the monotonic clock always moves
forward."
What I want is the system clock time, which *is* adjusted by NTP. I
know it's not guaranteed monotonic, but different computers should have
the same time (or be able to be synchronized to the same NTP time). And
it's "approximately monotonic". time_t is fine, as 32 bit hardware is
becoming scarce, and the application I'm working on will probably never
encounter any. (More than 32 bits of precision is required as I don't
want it to roll over every 42.5 days.)
I understand why some purposes would really want a monotonic time, but
that's not a strong constraint for me. But I do want it to be a long or
ulong. (I don't really care where 0 is. What I'm using now is:
alias long ClockT;
ClockT now() { return MonoTime.currTime(); }
And it's working fine during testing, but the documentation about the
setting of MonoTime bothers me.
More information about the Digitalmars-d-learn
mailing list