How to convert String "TimeOfDay(00:00)" in TimeOfDay

335

This worked for me:

time = time.split("(")[1].split(")")[0];
time = TimeOfDay(hour:int.parse(time.split(":")[0]),minute: int.parse(time.split(":")[1]));
Share:
335
Admin
Author by

Admin

Updated on December 26, 2022

Comments

  • Admin
    Admin over 1 year

    I have this String : "TimeOfDay(00:00)". How can I convert it to a variable of type TimeOfDay to be able to get its '.hour' and '.minute' attributes?.

    Another option would be split the string in a way to get only the values to after create a TimeOfDay in this way: "TimeOfDay(hour: (split hour), minute: (split minute)"

    How can I reach that? Can be any of the two ways...

    What I already tried: TimeOfDay(hour:int.parse(time.split(":")[0]),minute: int.parse(time.split(")")[1])); . But It gives me this error:

    Invalid radix-10 number (at character 1) TimeOfDay(00