Date class
A class that stores and manages day, month and year.
- Implemented types
- Annotations
-
- @immutable
Constructors
- Date(int day, int month, int year)
- Creates a Date object from day, month and year values. If the values are invalid, behaves like DateTime constructor, always converting to a valid date. I.e. Date(50, 40, 2000) will be converted to Date(20, 5, 2003). If you want to validate the input, use Date.isValid method.
- Date.fromDateTime(DateTime dateTime)
- Converts a DateTime to a Date.
- Date.parse(String dateString)
- Parses String to Date object. String must be formatted as ddmmyyyy. Performs validation. Throws FormatException when argument contains non-numbers.
- Date.parseIso8601(String dateString)
- Parses given String to a new Date object. Besides ISO 8601 works with every format of String that DateTime.parse would work with. Performs validation. Throws FormatException when the input can't be parsed.
- Date.today()
- Returns today's date.
- Date.tomorrow()
- Returns tomorrow's date.
- Date.yesterday()
- Returns yesterday's date.
Properties
- day → int
-
Returns day of the date represented by this object. Always in range
1; 31
.no setter - hashCode → int
-
The hash code for this object.
no setteroverride
- month → int
-
Returns month of the date represented by this object. Always in range
1; 12
.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- weekday → int
-
Returns weekday of the date represented by this object. Always in range
1; 7
, where 1 is Monday and 7 is Sunday.no setter - year → int
-
Returns year of the date represented by this object.
no setter
Methods
-
addDays(
int days) → Date -
Returns a new Date with given amount of days added to this.
days
can be negative, in this case subtraction will happen. -
compareTo(
Date other) → int -
Returns
0
if this is at the same date asother
,1
if this is afterother
and-1
if this is beforeother
.override -
copyWith(
{int? day, int? month, int? year}) → Date - Returns new Date modified with given input.
-
format(
List< String> formats) → String -
Formats this with a given input.
I.e. to get the String
"11-03-2002"
, you want to callDate(11, 3, 2002).format([dd, '-', mm, '-', yyyy])
. Available date modifiers are: -
isAfter(
Date other) → bool -
Checks if this is after
other
. -
isBefore(
Date other) → bool -
Checks if this is before
other
. -
isTheSameDate(
Date other) → bool -
Checks if this is the same date as
other
. -
isToday(
) → bool - Checks if this is today.
-
isTomorrow(
) → bool - Checks if this is tomorrow.
-
isYesterday(
) → bool - Checks if this is yesterday.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
subtractDays(
int days) → Date -
Returns a new Date with given amount of days subtracted from this.
days
can be negative, in this case addition will happen. -
toDateTime(
) → DateTime - Returns DateTime object with the date of this and time values at 00:00.
-
toIso8601(
{bool includeTime = true}) → String -
Returns an ISO8601 String representing this.
If
includeTime
is set totrue
, the time will be included, and the format will be "yyyy-mm-ddT00:00:00.000000". IfincludeTime
is set tofalse
, the time will be excluded, and the format will be "yyyy-mm-dd". -
toString(
) → String -
Returns this Date's object representations as String, with
format ddmmyyyy. For other formatting options, use format method.
override
Operators
-
operator +(
int days) → Date -
Returns a new Date with given amount of days added to this.
days
can be negative, in this case subtraction will happen. -
operator -(
int days) → Date -
Returns a new Date with given amount of days subtracted from this.
days
can be negative, in this case addition will happen. -
operator <(
Date other) → bool -
Checks if this is before
other
. -
operator <=(
Date other) → bool -
Checks if this is before or at the same day as
other
. -
operator ==(
dynamic other) → bool -
The equality operator.
override
-
operator >(
Date other) → bool -
Checks if this is after
other
. -
operator >=(
Date other) → bool -
Checks if this is after or at the same day as
other
.