将日期时间解析为JAVA日期 [英] Parse Datetime to JAVA Date
本文介绍了将日期时间解析为JAVA日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SqlRowSet
像 while(rs.next()){
myBean.setDateProp(rs.getString(4));
}
myBean的类型
DateProp
是 java.util.Date
,有没有办法转换(1月1日2013)
to java Date表示。
我已尝试过以下代码
SimpleDateFormat sdf = new SimpleDateFormat(dd-MMM-yyyy HH:mm:ss.SSS);
Date date = new Date();
try {
date = sdf.parse(2013年1月1日);
} catch(Exception e){
e.printStackTrace();
}
我得到 ParseException
SEVERE:java.text.ParseException:不可稀释日期:2013年1月1日
任何方向...
解决方案
SimpleDateFormat sdf = new SimpleDateFormat(dd MMM yyyy);
Date date = new Date();
try {
date = sdf.parse(2013年1月1日);
} catch(Exception e){
e.printStackTrace();
}
im getting the SQL Server datetime (1 Jan 2013) form the SqlRowSet
like
while (rs.next()) {
myBean.setDateProp(rs.getString(4));
}
the type of myBean
DateProp
is java.util.Date
, is there a way to convert (1 Jan 2013)
to java Date representation.
i have tried the following code
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss.SSS");
Date date=new Date();
try {
date = sdf.parse("1 Jan 2013");
} catch (Exception e) {
e.printStackTrace();
}
and i get the ParseException
SEVERE: java.text.ParseException: Unparseable date: "1 Jan 2013"
any directions...
解决方案
try this -
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
Date date=new Date();
try {
date = sdf.parse("1 Jan 2013");
}catch (Exception e) {
e.printStackTrace();
}
这篇关于将日期时间解析为JAVA日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文