我想在下面的代码中将String (returns string :odb.getCloseDate())
转换为Date。但我没有得到这个合作伙伴的输出"23/10/2013"
。请纠正我在哪里做错了。 在数据库表中的值是在这个formate:2013-06-30和im通过bean检索这个数据,即odb.getCloseDate()。现在我需要在这个合成器中显示这个日期,即23/10/2013。使用java在xls中将字符串转换为日期格式
HSSFCell row1 = row.createCell((short) j);
//row1.setCellType(row1.CELL_TYPE_NUMERIC);
try
{
//row1.setCellValue(Date.parse(odb.getCloseDate()));
DateFormat formatter;
Date date;
formatter = new SimpleDateFormat("dd/MM/yyyy");
row1.setCellValue(date = formatter.parse(odb.getCloseDate()));
}
catch (Exception e)
{
row1.setCellValue(odb.getCloseDate());
}
我所做的更改,按您的建议。但没有得到这个合成的输出23/10/2013 .. Plz帮助 –
删除cellType row1.setCellType(row1.CELL_TYPE_NUMERIC);将传入日期转换为字符串并将日期设置为字符串。 – newuser
我在上面的代码中注释了行row1.setCellType(row1.CELL_TYPE_NUMERIC)并进行了检查。但没用。产量不会像2013年10月23日那样。 –