The OpenD Programming Language

SysTime.fromUnixTime

Converts from unix time (i.e. seconds from midnight, January 1st, 1970 in UTC) to a SysTime.

The C standard does not specify the representation of time_t, so it is implementation defined. On POSIX systems, unix time is equivalent to time_t, but that's not necessarily true on other systems (e.g. it is not true for the Digital Mars C runtime). So, be careful when using unix time with C functions on non-POSIX systems.

struct SysTime
static @safe pure nothrow
fromUnixTime
(,
immutable TimeZone tz = LocalTime()
)

Parameters

unixTime long

Seconds from midnight, January 1st, 1970 in UTC.

tz TimeZone

The time zone for the SysTime that's returned.

Examples

import core.time : hours;
import std.datetime.date : DateTime;
import std.datetime.timezone : SimpleTimeZone, UTC;

assert(SysTime.fromUnixTime(0) ==
       SysTime(DateTime(1970, 1, 1), UTC()));

auto pst = new immutable SimpleTimeZone(hours(-8));
assert(SysTime.fromUnixTime(28800) ==
       SysTime(DateTime(1970, 1, 1), pst));

auto st1 = SysTime.fromUnixTime(1_198_311_285, UTC());
assert(st1 == SysTime(DateTime(2007, 12, 22, 8, 14, 45), UTC()));
assert(st1.timezone is UTC());
assert(st1 == SysTime(DateTime(2007, 12, 22, 0, 14, 45), pst));

auto st2 = SysTime.fromUnixTime(1_198_311_285, pst);
assert(st2 == SysTime(DateTime(2007, 12, 22, 8, 14, 45), UTC()));
assert(st2.timezone is pst);
assert(st2 == SysTime(DateTime(2007, 12, 22, 0, 14, 45), pst));

Meta