Note: Whereas the other constructors take in the given date/time, assume that it's in the given time zone, and convert it to hnsecs in UTC since midnight, January 1st, 1 A.D. UTC - i.e. std time - this constructor takes a std time, which is specifically already in UTC, so no conversion takes place. Of course, the various getter properties and functions will use the given time zone's conversion function to convert the results to that time zone, but no conversion of the arguments to this constructor takes place.
Adds the given number of years or months to this SysTime. A negative number will subtract.
Returns the difference between the two SysTimes in months.
Gives the result of adding or subtracting a core.time.Duration from this SysTime.
Gives the difference between two SysTimes.
Returns a std.datetime.date.Date equivalent to this SysTime.
Returns a std.datetime.date.DateTime equivalent to this SysTime.
Returns a std.datetime.date.TimeOfDay equivalent to this SysTime.
Gives the result of adding or subtracting a core.time.Duration from this SysTime, as well as assigning the result to this SysTime.
Adds the given number of years or months to this SysTime. A negative number will subtract.
Adds the given number of units to this SysTime. A negative number will subtract.
Converts this SysTime to a string with the format YYYY-MM-DDTHH:MM:SS.FFFFFFFTZ (where F is fractional seconds and TZ is the time zone).
Converts this SysTime to a string with the format YYYYMMDDTHHMMSS.FFFFFFFTZ (where F is fractional seconds and TZ is time zone).
Returns a SysTime with the same std time as this one, but with std.datetime.timezone.LocalTime as its time zone.
Returns a SysTime with the same std time as this one, but with given time zone as its time zone.
Converts this SysTime to a string with the format YYYY-Mon-DD HH:MM:SS.FFFFFFFTZ (where F is fractional seconds and TZ is the time zone).
Converts this SysTime to a string.
Returns a tm which represents this SysTime.
Returns a timespec which represents this SysTime.
Returns a timeval which represents this SysTime.
Returns a SysTime with the same std time as this one, but with UTC as its time zone.
Converts this SysTime to unix time (i.e. seconds from midnight, January 1st, 1970 in UTC).
Day of a Gregorian Month.
Day of a Gregorian Month.
The Xth day of the Gregorian Calendar that this SysTime is on.
Day of the week this SysTime is on.
Day of the year this SysTime is on.
Day of the year.
The last day in the month that this SysTime is in.
Returns whether DST is in effect for this SysTime.
SysTime for the last day in the month that this Date is in. The time portion of endOfMonth is always 23:59:59.9999999.
Fractional seconds past the second (i.e. the portion of a SysTime which is less than a second).
Fractional seconds past the second (i.e. the portion of a SysTime which is less than a second).
Hours past midnight.
Hours past midnight.
Whether the current year is a date in A.D.
Whether this SysTime is in a leap year.
The ISO 8601 week of the year that this SysTime is in.
The Julian day for this SysTime at the given time. For example, prior to noon, 1996-03-31 would be the Julian day number 2_450_173, so this function returns 2_450_173, while from noon onward, the Julian day number would be 2_450_174, so this function returns 2_450_174.
Minutes past the current hour.
Minutes past the current hour.
The modified Julian day for any time on this date (since, the modified Julian day changes at midnight).
Month of a Gregorian Year.
Month of a Gregorian Year.
Seconds past the current minute.
Seconds past the current minute.
The total hnsecs from midnight, January 1st, 1 A.D. UTC. This is the internal representation of SysTime.
The total hnsecs from midnight, January 1st, 1 A.D. UTC. This is the internal representation of SysTime.
Returns what the offset from UTC is for this SysTime. It includes the DST offset in effect at that time (if any).
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Creates a SysTime from a string with the format YYYY-MM-DDTHH:MM:SS.FFFFFFFTZ (where F is fractional seconds and TZ is the time zone). Whitespace is stripped from the given string.
Creates a SysTime from a string with the format YYYYMMDDTHHMMSS.FFFFFFFTZ (where F is fractional seconds and TZ is the time zone). Whitespace is stripped from the given string.
Creates a SysTime from a string with the format YYYY-Mon-DD HH:MM:SS.FFFFFFFTZ (where F is fractional seconds and TZ is the time zone). Whitespace is stripped from the given string.
Converts from unix time (i.e. seconds from midnight, January 1st, 1970 in UTC) to a SysTime.
import core.time : days, hours, seconds; import std.datetime.date : Date, DateTime; import std.datetime.timezone : SimpleTimeZone, UTC; const dt = DateTime(2018, 1, 1, 10, 30, 0); // make a specific point in time in the UTC timezone auto st = SysTime(dt, UTC()); assert(st.year == 2018); assert(st.hour == 10); // cast to convert assert(cast(DateTime) st == dt); assert(cast(Date) st == Date(2018, 1, 1)); // make a specific point in time in the New York timezone const ny = SysTime(dt, new immutable SimpleTimeZone(-5.hours, "America/New_York") ); assert(ny != st); assert(ny.hour == 10); // ISO standard time strings assert(st.toISOString() == "20180101T103000Z"); assert(st.toISOExtString() == "2018-01-01T10:30:00Z"); // add two days and 30 seconds st += 2.days + 30.seconds; assert(st.toISOExtString() == "2018-01-03T10:30:30Z");
$(RELATIVE_LINK2 .Clock.currTime, `Clock.currTime`) will return the current time as a SysTime.
SysTime is the type used to get the current time from the system or doing anything that involves time zones. Unlike std.datetime.date.DateTime, the time zone is an integral part of SysTime (though for local time applications, time zones can be ignored and it will work, since it defaults to using the local time zone). It holds its internal time in std time (hnsecs since midnight, January 1st, 1 A.D. UTC), so it interfaces well with the system time.
An hnsec (hecto-nanosecond) is 100 nanoseconds. There are 10,000,000 hnsecs in a second.
$(PANEL Unlike $(REF_SHORT DateTime,std,datetime,date), `SysTime` is not optimized for calendar-based operations, and getting individual units from it such as years or days is going to involve conversions and be less efficient. For calendar-based operations that don't care about time zones, then $(REF_SHORT DateTime,std,datetime,date) would be the type to use. For system time, use `SysTime`. )
Casting a SysTime to one of the following types will perform a conversion:
* std.datetime.date.Date * DateTime * TimeOfDay
To convert a Date or DateTime to a SysTime, use SysTime's constructor, and pass in the intended time zone with it (or don't pass in a std.datetime.timezone.TimeZone, and the local time zone will be used). Be aware, however, that converting from a DateTime to a SysTime will not necessarily be 100% accurate due to DST (one hour of the year doesn't exist and another occurs twice). To not risk any conversion errors, keep times as SysTimes. Aside from DST though, there shouldn't be any conversion problems.
$(PANEL For using time zones other than local time or UTC, use $(REF PosixTimeZone,std,datetime,timezone) on Posix systems (or on Windows, if providing the TZ Database files), and use $(REF WindowsTimeZone,std,datetime,timezone) on Windows systems. The time in `SysTime` is kept internally in hnsecs from midnight, January 1st, 1 A.D. UTC. Conversion error cannot happen when changing the time zone of a `SysTime`. $(REF LocalTime,std,datetime,timezone) is the $(REF_SHORT TimeZone,std,datetime,timezone) class which represents the local time, and `UTC` is the $(REF_SHORT TimeZone,std,datetime,timezone) class which represents UTC. `SysTime` uses $(REF_SHORT LocalTime,std,datetime,timezone) if no $(REF_SHORT TimeZone,std,datetime,timezone) is provided. For more details on time zones, see the documentation for $(REF_SHORT TimeZone,std,datetime,timezone), $(REF_SHORT PosixTimeZone,std,datetime,timezone), and $(REF_SHORT WindowsTimeZone,std,datetime,timezone). )
SysTime's range is from approximately 29,000 B.C. to approximately 29,000 A.D.