java String日期格式转换

SimpleDateFormat sdf = new SimpleDateFormat("yyyymmdd");
    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/mm/dd");
    String date = "20100701";
    String new_s = date.replaceAll("(\\d{4})(\\d{2})(\\d{2})", "$1/$2/$3");
    try {
        System.out.println(new_s);
        System.out.println(sdf1.format(sdf.parse(date)));
    } catch (ParseException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

 

你可能感兴趣的:(java)