parse static method

Moment parse({
  1. required String string,
})

Parses a Moment from a string in the format "yyyy/MM/dd-HH:mm:ss".

Throws if the string doesn't match the expected pattern. For a non-throwing alternative, see tryParse.

final m = Moment.parse(string: '2025/06/15-14:30:00');

Implementation

static Moment parse({required String string}) {
  var split1 = string.split('-');
  var dates = split1[0].split('/');
  var times = split1[1].split(':');
  return Moment(
    year: int.parse(dates[0]),
    month: int.parse(dates[1]),
    date: int.parse(dates[2]),
    hour: int.parse(times[0]),
    minute: int.parse(times[1]),
    second: int.parse(times[2]),
  );
}