View source code
Display the source code in std/datetime.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Struct std.datetime.DateTime
Combines the Date
and TimeOfDay
structs to give an object
which holds both the date
and the time. It is optimized for calendar-based
operations and has no concept of time zone. For an object
which is
optimized for time operations based on the system time, use
SysTime
. SysTime
has a concept of time zone and has much higher
precision (hnsecs).
is intended primarily for calendar-based
uses rather than precise time operations.
DateTime
Constructors
Name | Description |
---|---|
this
|
|
this
|
Properties
Name | Type | Description |
---|---|---|
date
[get]
|
Date |
The date portion of DateTime .
|
date
[set]
|
const(Date) |
The date portion of DateTime .
|
day
[set]
|
int |
Day of a Gregorian Month .
|
day
[get]
|
ubyte |
Day of a Gregorian Month .
|
dayOfGregorianCal
[get]
|
int |
The Xth day of the Gregorian Calendar that this DateTime is on.
|
dayOfGregorianCal
[set]
|
int |
The Xth day of the Gregorian Calendar that this DateTime is on.
Setting this property does not affect the time portion of
DateTime .
|
dayOfWeek
[get]
|
DayOfWeek |
Day of the week this DateTime is on.
|
dayOfYear
[get]
|
ushort |
Day of the year this DateTime is on.
|
dayOfYear
[set]
|
int |
Day of the year .
|
daysInMonth
[get]
|
ubyte |
The last day in the month that this DateTime is in.
|
endOfMonth
[get]
|
DateTime |
DateTime for the last day in the month that this DateTime is
in. The time portion of endOfMonth is always 23:59:59.
|
hour
[get]
|
ubyte |
Hours past midnight. |
hour
[set]
|
int |
Hours past midnight. |
isAD
[get]
|
bool |
Whether the current year is a date in A.D.
|
isLeapYear
[get]
|
bool |
Whether this DateTime is in a leap year .
|
isoWeek
[get]
|
ubyte |
The ISO 8601 week of the year that this DateTime is in.
|
julianDay
[get]
|
long |
The Julian day for this
DateTime 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.
|
max
[get]
|
DateTime |
Returns the DateTime farthest in the future which is representable
by DateTime .
|
min
[get]
|
DateTime |
Returns the DateTime farthest in the past which is representable by
DateTime .
|
minute
[get]
|
ubyte |
Minutes past the hour .
|
minute
[set]
|
int |
Minutes past the hour .
|
modJulianDay
[get]
|
long |
The modified Julian day for any
time on this date (since, the modified Julian day changes at midnight).
|
month
[set]
|
Month |
Month of a Gregorian Year.
|
month
[get]
|
Month |
Month of a Gregorian Year.
|
second
[set]
|
int |
Seconds past the minute .
|
second
[get]
|
ubyte |
Seconds past the minute .
|
timeOfDay
[set]
|
const(TimeOfDay) |
The time portion of DateTime .
|
timeOfDay
[get]
|
TimeOfDay |
The time portion of DateTime .
|
year
[set]
|
int |
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C. |
year
[get]
|
short |
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C. |
yearBC
[set]
|
int |
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
|
yearBC
[get]
|
short |
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
|
Methods
Name | Description |
---|---|
add
|
Adds the given number of years or months to this DateTime . A
negative number will subtract.
|
diffMonths
|
Returns the difference between the two DateTimes in months. |
fromISOExtString
|
Creates a DateTime from a string with the format
YYYY-MM-DDTHH:MM:SS. Whitespace is stripped from the given string.
|
fromISOString
|
Creates a DateTime from a string with the format YYYYMMDDTHHMMSS.
Whitespace is stripped from the given string.
|
fromSimpleString
|
Creates a DateTime from a string with the format
YYYY-Mon-DD HH:MM:SS. Whitespace is stripped from the given string.
|
opBinary
|
Gives the result of adding or subtracting a duration from this
DateTime .
|
opBinary
|
Gives the difference between two DateTimes. |
opCmp
|
Compares this DateTime with the given .
|
opOpAssign
|
Gives the result of adding or subtracting a duration from this
DateTime , as well as assigning the result to this DateTime .
|
roll
|
Adds the given number of units to this DateTime . A negative number
will subtract.
|
roll
|
Adds the given number of years or months to this DateTime . A
negative number will subtract.
|
toISOExtString
|
Converts this DateTime to a string with the format
YYYY-MM-DDTHH:MM:SS.
|
toISOString
|
Converts this DateTime to a string with the format YYYYMMDDTHHMMSS.
|
toSimpleString
|
Converts this DateTime to a string with the format
YYYY-Mon-DD HH:MM:SS.
|
toString
|
Converts this DateTime to a string.
|
Authors
Jonathan M Davis and Kato Shoichi