java - 如何在文本小部件中读取 LocalTime 变量
问题描述
import org.eclipse.swt.widgets.Text;
...
private Text textora;
...
LocalTime ora = textora.getLocalTime();
我无法从文本格式中读取 LocalTime 变量以进行输入
错误:
Multiple markers at this line
- The method getLocalTime() is undefined for the
type Text
- The method getTime() is undefined for the type
Text
解决方案
SWTText
控件只是纯文本,只有一种getText
方法可以获取输入的字符串。要将文本转换为LocalTime
您必须解析文本:
String timeStr = textora.getString();
LocalTime time = LocalTime.parse(timeStr);
parse
DateTimeParseException
如果字符串不是有效时间,将抛出异常。
您还可以使用 SWTDateTime
控件来允许输入时间:
import org.eclipse.swt.widgets.DateTime;
...
DateTime dt = new DateTime(parent, SWT.TIME);
...
LocalTime time = LocalTime.of(dt.getHours(), dt.getMinutes(), dt.getSeconds());
推荐阅读
- git - 在未来的项目中重用 gulpfile
- laravel - 导入时如何发送电子邮件?
- aws-lambda - 在 AWS 控制台 (web) 中设置 lambda 的处理程序
- sql - 使用具有不同行数的两个选择查询插入数据
- group-by - 如何在 KNIME 中添加 2 行重复行的值?
- css - 基于侧边内容的 CSS Flexbox 图像缩放
- mule - Dataweave,如何在生成 csv 时删除额外的 \n?
- kubernetes - 有没有办法强制删除 webhook 失败的 crd?
- google-cloud-platform - 使用 python 连接到 google-cloud-platform mysql 服务并查询 Cloud SQL Admin API
- ruby - psql - 终端认证访问问题