将字符串转换为日期java错误“不兼容的类型"; [英] convert string to date java error "incompatible types"
问题描述
我成功地将JDateChooser中的日期添加到带有以下行的字符串中:
I success to get my date from JDateChooser into a string with this line:
String d1 = ((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText();
我想知道是否有任何方法可以从JDateChooser获取日期?
I want to know if there is any method to get a date from a JDateChooser ?
我试图将此字符串转换为日期,但第三行出现错误.
I tried to convert this string into a date , and i have an error in the third line .
不兼容的类型:java.util.date无法转换为java.sql.Date"
"incompatible types : java.util.date cannot be converted to java.sql.Date "
String s = "2011-07-08";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(s);
我必须导入java.util.Date,但是我在同一行有另一个错误
i have to import the java.util.Date , But i have another error in the same line
未报告的异常ParseException;必须被抓到或声明要扔掉
unreported exception ParseException ; must be caught or declared to be thrown
推荐答案
您已导入
java.sql.Date
代替
java.util.Date
将 import
语句更改为适当的类型,即. java.util.Date
.
Change the import
statement to the appropriate type, ie. java.util.Date
.
这篇关于将字符串转换为日期java错误“不兼容的类型";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!