悠然哈哈哈

导航

日期格式转换

 public Date buildTime(String blanceTime) {
        String[] parsePatterns = {"yyyy-MM-dd","yyyy/MM/dd"};
        Date formattedDate = null;
        try {
            //防止被Excel 转换成数字
            String regex = "^(\\d+(\\.\\d+)?)$";
            if (blanceTime.matches(regex)) {
                Date dateToReturn = DateUtil.getJavaDate(Integer.parseInt(blanceTime));
                formattedDate = dateFormat.parse(dateFormat.format(dateToReturn));
            } else {
                formattedDate = DateUtils.parseDateStrictly(blanceTime, parsePatterns);
            }
        } catch (Exception e) {
            logger.error("解析日期格式失败:",e);
        }
        return formattedDate;
    }

  

posted on 2024-11-13 10:53  悠然886  阅读(1)  评论(0编辑  收藏  举报