java时间格式转换任意格式

例如:20180918/120023转换成2018-09-18 12:00:23

    //时间格式转换
    public String getNomalTime(String oldTime){
        String newTime = "";
        if(StringUtils.isNotBlank(oldTime)){
            String reg = "(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})";
            newTime = oldTime.replace("/","").replaceAll(reg, "$1-$2-$3T$4:$5:$6");
        }

        return  newTime;
    }

 

posted @ 2019-04-12 09:57  kerala  阅读(1060)  评论(0编辑  收藏  举报