刚刚学java不久,遇到了很棘手的问题,请高手作解。用poi方法操作Excel时,类似这样的[9:00]时间怎么才能成功显示出来?目前我只能将日期和时间都显示出来,但就是不能单独现实时间。我的方法如下:
//String to Date
Date Datetemp = DateFormat.getDateTimeInstance().parse(”2007/1/3 09:00:00”); //Create Style
HSSFCellStyle cellStyle = workBook.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm")); ★1 //Insert
Cell.setCellValue(datetemp);
Cell.setCellStyle(cellStyle); 如果将★1的Format修改为「h:mm」的话,表面上显示的是「9:00」,但实际单元格里面出来的是
「955065:00:00」。怎么样才能正确的现实「9:00」,请高手作答。
//String to Date
Date Datetemp = DateFormat.getDateTimeInstance().parse(”2007/1/3 09:00:00”); //Create Style
HSSFCellStyle cellStyle = workBook.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm")); ★1 //Insert
Cell.setCellValue(datetemp);
Cell.setCellStyle(cellStyle); 如果将★1的Format修改为「h:mm」的话,表面上显示的是「9:00」,但实际单元格里面出来的是
「955065:00:00」。怎么样才能正确的现实「9:00」,请高手作答。
String formatString = "hh:mm:ss";
Format format = new SimpleDateFormat(formatString);
String st = format.format(date);
System.out.println(st);这样,对于formatString我可以在配置文件中随意控制。代码中放入cell都是统一的String型。
String出力的结果一定会有单引号出现,这不是我想要的结果