JAVA中的时间转化

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);

 

posted @ 2018-05-30 16:48  林被熊烟岛  阅读(142)  评论(0编辑  收藏  举报