If your input is already an integer, you can do integer arithmetic to extract the parts:
void main() {
var timestamp = 230523110326;
var components = <int>[];
for (var i = 0; i < 6; i += 1) {
components.add(timestamp % 100);
timestamp = timestamp ~/ 100;
}
var [seconds, minutes, hour, twoDigitYear, month, day] = components;
var year = fromTwoDigitYear(twoDigitYear); // See below.
var dateTime = DateTime(year, month, day, hour, minutes, seconds);
print(dateTime); // Prints: 2023-05-23 11:03:26.000
}
See https://stackoverflow.com/a/76273568/ for how to convert a two-digit year to a four-digit yaer.
Finally, I'd like to point out that it's unclear whether your timestamp format is supposed to be in a ddMMyy
or in a yyMMdd
format because your particular example ambiguously uses 23
for both the day and two-digit year. The code above assumes ddMMyy
to match the order you listed, but yyMMdd
would be more sensible for an integer timestamp since it would allow comparing (most) timestamps with an integer comparison. (However, the use of two-digit years instead of four-digit years means that such comparisons wouldn't work properly for years before 2000.)