How to get current time as long or ulong?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 5 11:47:04 PDT 2016


On Tuesday, July 05, 2016 18:25:17 John via Digitalmars-d-learn wrote:
> On Tuesday, 5 July 2016 at 18:16:31 UTC, Charles Hixson wrote:
> > I've been reading std.datetime documentation backwards and
> > forwards, but if the information is there, I've been missing it.
> >
> > How do I get the current time as a long?
> >
> > Clock.currTime() returns a SysTime, and while currently I can
> > convert that to a long, this is because I looked into the code.
> > What's the supported way?  All the documentation seems to be
> > based around auto, which is great if you don't need to store it
> > in memory with a defined number of bits allocated...but lousy
> > if you do.   (E.g., I don't want to store a time zone, just the
> > UTC time.
> >
> > What I'm looking for is the opposite of the "FromUnixTime"
> > function.
>
> Clock.currTime.stdTime

That would give you the badly named "std" time and not "unix" time. "std"
time is what SysTime uses internally and is the number of hecto-nanoseconds
since midnight, January 1st, 1 A.D., whereas unix time is the number of
seconds since midnight, January 1st, 1970. What SysTime uses is essentially
the same thing that C# uses with its DateTime type with the poor name of
"ticks", whereas unix time is what you normally get with C - though
technically, if you're not on a POSIX system, there is no guarantee that
time_t is equivalent to unix time - it just usually is.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list