如何在Flutter中将String转换为TimeOfDay? [英] How to convert String to TimeOfDay in flutter?

查看:245
本文介绍了如何在Flutter中将String转换为TimeOfDay?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,假设是 16:00,我想将其转换为TimeOfDay类型。
我检查了文档,它仅提供从DateTime到TimeOfDay的转换程序,但是我找不到从String转换为TimeOfDay的方法。

I have a String, lets say '16:00' and I want to convert it to a TimeOfDay type. I checked the documentation and it only provides a conversor from DateTime to TimeOfDay, but I cant find a way to convert from String to TimeOfDay.

推荐答案

尝试一下

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

这对我有用。

这篇关于如何在Flutter中将String转换为TimeOfDay?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆