日期格式不足10补0

public static String fillDateWillZero(String dateStr) {
        int start = dateStr.indexOf("-");
        int end = dateStr.lastIndexOf("-");
        String month = dateStr.substring(start + 1, end);
        if (month.length() == 1) {
            month = "0" + month;
        }
        String day = dateStr.substring(end + 1);
        if (day.length() == 1) {
            day = "0" + day;
        }
        System.out.print("月:" + month + "           ");
        System.out.println("日:" + day);
        return dateStr.substring(0, start + 1) + month + "-" + day;
    }

你可能感兴趣的:(实用代码)