我做这个模块的导入导出功能,想给时间format一下,但是不知道怎么写,
这是导入之前可以预览的方法:
/**
导入预览
@return
@throws Exception
*/
public String addExcelSocial() throws Exception {
path = ServletActionContext.getRequest().getRealPath("/leading");
String today=DateUtil.getTimeStamp();
fileFileName="Excel3_"+today+"."+"xls";
File destFile = new File(path, fileFileName);
OutputStream os = new FileOutputStream(destFile);
InputStream is = new FileInputStream(file);
byte[] buffer = new byte[1024];
int length = 0;
while(-1 != (length = is.read(buffer))){
os.write(buffer, 0, length);
}
is.close();
os.close();
String[] names = new String[] { "姓名", "身份证号","参保地","退伍证编号", "参保时间",
"录入时间","录入人员","修改时间","修改人员" };
LinkedHashMap<String, String> fieldMaps = new LinkedHashMap<String, String>();
fieldMaps.put("socialName", "姓名");
fieldMaps.put("socialIdNumber", "身份证号");
fieldMaps.put("socialAddress", "参保地");
fieldMaps.put("dischargeId", "退伍证编号");
fieldMaps.put("insuredTime", "参保时间");
fieldMaps.put("crateTime", "录入时间");
fieldMaps.put("entrypersonnel", "录入人员");
fieldMaps.put("modifyTime", "修改时间");
fieldMaps.put("modifyStaff", "修改人员");
List<Social> list = ExcelUitl.importoutSocial(destFile,names,fieldMaps);
List<Social> resultlist1 = new ArrayList<Social>();
List<Social> resultlist2 = new ArrayList<Social>();
List<Social> resultlist3 = new ArrayList<Social>();
for (Social sl : list) {
if ("".equals(sl.getSocialName())
|| "".equals(sl.getSocialIdNumber())
|| sl.getSocialName() == null
|| sl.getSocialIdNumber()== null){
resultlist1.add(sl);
}
List<Social> staa=socialService.getBySocialNme(sl.getSocialName());
if(staa.size()> 0){
resultlist2.add(sl);
}
List<Social> stm=socialService.getBySocialNumber(sl.getSocialIdNumber());
if(stm.size()>0){
resultlist3.add(sl);
}
}
if (resultlist1.size() > 0) {
if (resultlist1.size() > 300) {
resultlist = resultlist1.subList(0, 300);
} else {
resultlist = resultlist1;
}
result_number = 1;
} else if (resultlist1.size() == 0 && resultlist2.size() > 0) {
if (resultlist2.size() > 300) {
resultlist = resultlist2.subList(0, 300);
} else {
resultlist = resultlist2;
}
result_number = 2;
}else if(resultlist1.size() == 0 && resultlist2.size() == 0 && resultlist3.size() > 0){
if (resultlist3.size() > 300) {
resultlist = resultlist3.subList(0, 300);
} else {
resultlist = resultlist3;
}
result_number = 3;
}else{
if (list.size() > 300) {
resultlist = list.subList(0, 300);
} else {
resultlist = list;
}
result_number = 4;
}
return "preview";
}
这样:
Date dtNow = new Date();
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String myDt = sdf1.format(dtNow.getTime());
System.out.println(myDt);
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
myDt = sdf2.format(dtNow.getTime());
System.out.println(myDt);
还是没解决大佬
把时间转化成字符串呗,然后再写入到excel不就完事了