View source code
Display the source code in std/datetime/date.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
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.
Struct std.datetime.date.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). DateTime
is intended primarily for calendar-based uses rather than precise time
operations.
struct DateTime
;
Constructors
Name | Description |
---|---|
this
(date, tod)
|
|
this
(year, month, day, hour, minute, second)
|
Properties
Name | Type | Description |
---|---|---|
date [get]
|
Date | The date portion of DateTime .
|
date [set]
|
Date | The date portion of DateTime .
|
day [get]
|
ubyte | Day of a Gregorian Month. |
day [set]
|
int | 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.
|
isoWeekYear [get]
|
short | The year of the ISO 8601 week calendar 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 [get]
|
Month | Month of a Gregorian Year. |
month [set]
|
Month | Month of a Gregorian Year. |
second [get]
|
ubyte | Seconds past the minute. |
second [set]
|
int | Seconds past the minute. |
timeOfDay [get]
|
TimeOfDay | The time portion of DateTime .
|
timeOfDay [set]
|
TimeOfDay | The time portion of DateTime .
|
year [get]
|
short | Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C. |
year [set]
|
int | Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C. |
yearBC [get]
|
short | Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C. |
yearBC [set]
|
int | Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C. |
Methods
Name | Description |
---|---|
add
(value, allowOverflow)
|
Adds the given number of years or months to this DateTime ,
mutating it. A negative number will subtract.
|
diffMonths
(rhs)
|
Returns the difference between the two DateTime s in months.
|
fromISOExtString
(isoExtString)
|
Creates a DateTime from a string with the format
YYYY-MM-DDTHH:MM:SS. Whitespace is stripped from the given string.
|
fromISOString
(isoString)
|
Creates a DateTime from a string with the format YYYYMMDDTHHMMSS.
Whitespace is stripped from the given string.
|
fromSimpleString
(simpleString)
|
Creates a DateTime from a string with the format
YYYY-Mon-DD HH:MM:SS. Whitespace is stripped from the given string.
|
opBinary
(duration)
|
Gives the result of adding or subtracting a Duration
from this DateTime .
|
opBinary
(rhs)
|
Gives the difference between two DateTime s.
|
opCmp
(rhs)
|
Compares this DateTime with the given DateTime .
|
opOpAssign
(duration)
|
Gives the result of adding or subtracting a duration from this
DateTime , as well as assigning the result to this
DateTime .
|
roll
(value, allowOverflow)
|
Adds the given number of years or months to this DateTime ,
mutating it. A negative number will subtract.
|
roll
(value)
|
Adds the given number of units to this DateTime , mutating it. A
negative number will subtract.
|
toISOExtString
()
|
Converts this DateTime to a string with the format
YYYY-MM-DDTHH:MM:SS . If writer is set, the resulting
string will be written directly to it.
|
toISOString
()
|
Converts this DateTime to a string with the format YYYYMMDDTHHMMSS .
If writer is set, the resulting string will be written directly to it.
|
toSimpleString
()
|
Converts this DateTime to a string with the format
YYYY-Mon-DD HH:MM:SS . If writer is set, the resulting
string will be written directly to it.
|
toString
()
|
Converts this DateTime to a string.
|
Example
import core .time : days, seconds;
auto dt = DateTime(2000, 6, 1, 10, 30, 0);
writeln(dt .date); // Date(2000, 6, 1)
writeln(dt .timeOfDay); // TimeOfDay(10, 30, 0)
writeln(dt .dayOfYear); // 153
writeln(dt .dayOfWeek); // DayOfWeek.thu
dt += 10 .days + 100 .seconds;
writeln(dt); // DateTime(2000, 6, 11, 10, 31, 40)
writeln(dt .toISOExtString()); // "2000-06-11T10:31:40"
writeln(dt .toISOString()); // "20000611T103140"
writeln(dt .toSimpleString()); // "2000-Jun-11 10:31:40"
writeln(DateTime .fromISOExtString("2018-01-01T12:00:00")); // DateTime(2018, 1, 1, 12, 0, 0)
writeln(DateTime .fromISOString("20180101T120000")); // DateTime(2018, 1, 1, 12, 0, 0)
writeln(DateTime .fromSimpleString("2018-Jan-01 12:00:00")); // DateTime(2018, 1, 1, 12, 0, 0)
Authors
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.