timestamp property
int
get
timestamp
Gets the timestamp from a time-based UUID (version 1).
Returns:
- Timestamp in 100-nanosecond intervals since UUID epoch
- Throws UnsupportedError if not a version 1 UUID
The UUID epoch is October 15, 1582 00:00:00 UTC.
Example
final uuid = Uuid.timeBasedUuid();
if (uuid.version == 1) {
final timestamp = uuid.timestamp;
print('UUID generated at: ${DateTime.fromMillisecondsSinceEpoch(timestamp ~/ 10000)}');
}
Implementation
int get timestamp {
if (version != 1) {
throw UnsupportedError('Timestamp is only available for version 1 UUIDs');
}
final timeLow = _mostSigBits >> 32;
final timeMid = (_mostSigBits >> 16) & BigInteger.fromInt(0xFFFF);
final timeHi = _mostSigBits & BigInteger.fromInt(0x0FFF);
return ((timeHi << 48) | (timeMid << 32) | timeLow).toInt();
}