A workaround for a date object without time. Since dart only has DateTime.
This is generally a wrapper around DateTime in dart, so it has all the methods DateTime has.
For example:
final now = Date.now();
final berlinWallFell = Date(1989, 11, 9);
final moonLanding = Date.parse('1969-07-20');
You can use properties to get the individual units of a DateTime object.
print(berlinWallFell.year); // 1989
print(berlinWallFell.month); // 11
print(berlinWallFell.day); // 9
The Date class contains methods for comparing Date chronologically, such as isAfter, isBefore, and isAtSameMomentAs.
print(berlinWallFell.isAfter(moonLanding)); // true
print(berlinWallFell.isBefore(moonLanding)); // false
print(dDay.isAtSameMomentAs(localDay)); // true
Use the add and subtract methods with a Duration object to create a Date object based on another. For example, to find the point in time that is 36 hours after now, you can write:
final now = Date.now();
final later = now.add(const Duration(hours: 36));
To find out how much time is between two Date objects use difference, which returns a Duration object:
final difference = berlinWallFell.difference(moonLanding);
print(difference.inDays); // 7416
Constructs a Date instance specified.
Date(int year, [int month = 1, int day = 1])
Constructs a Date instance with current date.
Date.now()
The day of the month [1..31]
The month [1..12]
The year.
Returns a new Date instance with duration added to this.
Compares this Date object to other, returning zero if the values are equal.
Returns a Duration with the difference when subtracting other from this.
Returns true if this occurs after other.
Returns true if this occurs at the same moment as other.
Returns true if this occurs before other.
Returns a new Date instance with duration subtracted from this.
Returns a human-readable string for this instance
Constructs a new Date instance based on formattedString.
Constructs a new Date instance based on formattedString.