Thread overview
How to get current time as long or ulong?
Jul 05, 2016
Charles Hixson
Jul 05, 2016
John
Jul 05, 2016
Jonathan M Davis
Jul 05, 2016
ag0aep6g
Jul 06, 2016
yawniek
July 05, 2016
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.

July 05, 2016
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
July 05, 2016
On 07/05/2016 08:16 PM, Charles Hixson via Digitalmars-d-learn wrote:
> What I'm looking for is the opposite of the "FromUnixTime" function.

That would be the "toUnixTime" method then, I suppose.

https://dlang.org/phobos/std_datetime.html#.SysTime.toUnixTime
July 05, 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

July 06, 2016
On Tuesday, 5 July 2016 at 18:16:31 UTC, Charles Hixson wrote:
> What I'm looking for is the opposite of the "FromUnixTime" function.

i often use

long toNsUnixTime(SysTime t)
{
  return (t.stdTime - 621_355_968_000_000_000L)*100;
}
as a helper. any chance that something like this can be put into phobos?
its needed to work with external libraries or network services that expect this format.