date_type

Creator: coderz1093

Last updated:

0 purchases

date_type Image
date_type Images

Languages

Categories

Add to Cart

Description:

date type

A workaround for a date object without time. Since dart only has DateTime.
Usage #
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');
copied to clipboard
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
copied to clipboard
Comparing Date objects #
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
copied to clipboard
Using Date with Duration #
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));
copied to clipboard
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
copied to clipboard
Constructors #
Constructs a Date instance specified.
Date(int year, [int month = 1, int day = 1])
copied to clipboard
Constructs a Date instance with current date.
Date.now()
copied to clipboard
Properties #
day → int #
The day of the month [1..31]
month → int #
The month [1..12]
year → int #
The year.
Methods #
add(Duration duration) → Date #
Returns a new Date instance with duration added to this.
compareTo(Date other) → int #
Compares this Date object to other, returning zero if the values are equal.
difference(Date other) → Duration #
Returns a Duration with the difference when subtracting other from this.
isAfter(Date other) → bool #
Returns true if this occurs after other.
isAtSameMomentAs(Date other) → bool #
Returns true if this occurs at the same moment as other.
isBefore(Date other) → bool #
Returns true if this occurs before other.
subtract(Duration duration) → Date #
Returns a new Date instance with duration subtracted from this.
toString() → String #
Returns a human-readable string for this instance
Static Methods #
parse(String formattedString) → Date #
Constructs a new Date instance based on formattedString.
tryParse(String formattedString) → Date? #
Constructs a new Date instance based on formattedString.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.