1. 把yyyyMMddHHmmss 变成date型
String startTime = params.get("startTime").toString(); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); LocalDateTime startLocalDate = LocalDateTime.parse(startTime,dtf); ZoneId zone = ZoneId.systemDefault(); Instant sInstant = startLocalDate.atZone(zone).toInstant(); Date startDate = Date.from(sInstant);
System.out.println(startDate);
最终结果:
2.把yyyy-MM-dd HH:mm:ss变成date型
String dispatchTime = workOrderInfo.get("DISPATCH_TIME"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); ParsePosition pos = new ParsePosition(0); Date dispatchTimeDate = sdf.parse(dispatchTime, pos);
最终结果:
3.把系统时间转化成yyyyMMdd
Date day = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd"); String fileNameSuffix = df.format(day);