Instant class Absolute times
Represents a single instant in time as a Timespan since January 1, 1970 UTC.
In general, this will be more useful when converted to an OffsetDateTime or a ZonedDateTime.
var instant = Instant.now();
instant.atOffset(ZoneOffset(-7));
instant.inTimezone('America/Phoenix');
- Implemented types
- Annotations
-
- @immutable
Constructors
- Instant.fromDateTime(DateTime dateTime)
- Creates an instant from a DateTime.
- Instant.fromUnix(Timespan unixTimestamp)
-
Creates an instant given a time since midnight, January 1, 1970 UTC.
const
- Instant.now()
- Creates an instant for the current time.
- Instant.parse(String isoString)
-
Parses an
Instantfrom an ISO-8601 formatted string.factory
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- unixTimestamp → Timespan
-
The amount of time since midnight, January 1, 1970 UTC.
final
Methods
-
atOffset(
[ZoneOffset? offset]) → OffsetDateTime -
Converts this to an OffsetDateTime with the given offset.
inherited
-
compareTo(
HasInstant other) → int -
Compares this to another
HasInstant.inherited -
inTimezone(
[String? zoneId]) → ZonedDateTime -
Converts this to a ZonedDateTime in the time zone given by
zoneId.inherited -
minusTimespan(
Timespan t) → Instant - Subtracts a Timespan.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
plusTimespan(
Timespan t) → Instant - Adds a Timespan.
-
quantize(
Timespan amount) → Instant -
Rounds this to a value divisible by
amount. -
timespanUntil(
HasInstant other) → Timespan -
Finds the amount of time between this and another instant in time.
inherited
-
toDateTime(
) → DateTime - Converts this to a DateTime in the local time zone.
-
toInstant(
) → Instant - Returns this unchanged.
-
toLocal(
) → LocalDateTime - Converts this to a LocalDateTime.
-
toString(
) → String -
Formats this as an ISO 8601 timestamp.
override
Operators
-
operator +(
Timespan t) → Instant - Adds a Timespan.
-
operator -(
Timespan t) → Instant - Subtracts a Timespan.
-
operator <(
HasInstant other) → bool -
Less than operator.
inherited
-
operator <=(
HasInstant other) → bool -
Less than or equals operator.
inherited
-
operator ==(
Object other) → bool -
The equality operator.
override
-
operator >(
HasInstant other) → bool -
Greater than operator.
inherited
-
operator >=(
HasInstant other) → bool -
Greater than or equals operator.
inherited