toTimestamp method
Returns a timestamp of this DateTime.
If toUtc
is true the this DateTime is converted to the
UTC timezone and the result will be yyyyMMddTHHmmss.mmmuuuZ
.
If includeFractions
is true then the milliseconds and microseconds
will be included in the result, otherwise they will be left out.
With includeFractions
yyyyMMddTHHmmss.mmmuuu
Without includeFractions
yyyyMMddTHHmmss
Implementation
String toTimestamp({
bool toUtc = true,
bool includeFractions = true,
}) {
final date = toUtc ? this.toUtc() : this;
var res = date.toIso8601String().replaceAll(RegExp("[-:]*"), "");
if (includeFractions) return res;
res = res.substring(0, res.indexOf("."));
return "$res${toUtc ? "Z" : ""}";
}