- 报错异常:
java.text.ParseException: Unparseable date: "1" at java.text.DateFormat.parse(DateFormat.java:366) at org.hesper.microservice.portal.utils.TimeUtil.toDate(TimeUtil.java:80)
- 原因:
因为Excel 导入的时间是以1900 年
为原点的,而变成数字的日期则是与 1900 年之间经过的天数差值。 - 解决方案:
Calendar calendar = new GregorianCalendar(1900,0,-1);
int intDay = Integer.parseInt(day);
Date dd = DateUtils.addDays(calendar.getTime(),intDay);
//对日期格式化操作
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(“YYYY-MM-dd HH:mm:ss”);
return simpleDateFormat.format(dd);