Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在文本小部件中读取LocalTime变量_Java_Eclipse_Swt - Fatal编程技术网

Java 如何在文本小部件中读取LocalTime变量

Java 如何在文本小部件中读取LocalTime变量,java,eclipse,swt,Java,Eclipse,Swt,我无法从文本格式中读取LocalTime变量进行输入 错误: import org.eclipse.swt.widgets.Text; ... private Text textora; ... LocalTime ora = textora.getLocalTime(); SWTText控件只是纯文本,只有一个getText方法来获取输入的字符串。要将文本转换为LocalTime,您必须解析文本: String timeStr=textora.getString();

我无法从文本格式中读取LocalTime变量进行输入

错误:

  import org.eclipse.swt.widgets.Text;
  ...
  private Text textora;
   ...
  LocalTime ora = textora.getLocalTime();

SWT
Text
控件只是纯文本,只有一个
getText
方法来获取输入的字符串。要将文本转换为
LocalTime
,您必须解析文本:

String timeStr=textora.getString();
LocalTime=LocalTime.parse(timeStr);
如果字符串不是有效时间,
parse
将抛出
DateTimeParseException
异常

您还可以使用SWT
DateTime
控件来允许输入时间:

import org.eclipse.swt.widgets.DateTime;
...
DateTime dt=新的DateTime(父级,SWT.TIME);
...
LocalTime time=LocalTime.of(dt.getHours(),dt.getMinutes(),dt.getSeconds());

SWT
Text
控件只是纯文本,只有一个
getText
方法来获取输入的字符串。要将文本转换为
LocalTime
,您必须解析文本:

String timeStr=textora.getString();
LocalTime=LocalTime.parse(timeStr);
如果字符串不是有效时间,
parse
将抛出
DateTimeParseException
异常

您还可以使用SWT
DateTime
控件来允许输入时间:

import org.eclipse.swt.widgets.DateTime;
...
DateTime dt=新的DateTime(父级,SWT.TIME);
...
LocalTime time=LocalTime.of(dt.getHours(),dt.getMinutes(),dt.getSeconds());

Text
只是纯文本,只有一个
getText
方法。您必须解析该文本才能获得日期。如果希望用户输入日期,您可能还需要查看SWT
DateTime
控件。我不想要日期,但time
DateTime
既有日期也有时间。对于
Text
您仍然需要解析时间。
Text
只是纯文本,只有
getText
方法。您必须解析该文本才能获得日期。如果希望用户输入日期,您可能还需要查看SWT
DateTime
控件。我不想要日期,但time
DateTime
既有日期也有时间。对于
Text
您仍然需要解析时间。
Multiple markers at this line
- The method getLocalTime() is undefined for the 
 type Text
- The method getTime() is undefined for the type 
 Text