Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
996 views
in Technique[技术] by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This worked for me:

time = time.split("(")[1].split(")")[0];
time = TimeOfDay(hour:int.parse(time.split(":")[0]),minute: int.parse(time.split(":")[1]));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...