本世纪,巧合的年月日

public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Calendar calendar = Calendar.getInstance();
        for (int y = 2000; y < 2100; y++) {
            String year = String.valueOf(y);
            //设置月份,因为月份从0开始,所以用month - 1
            calendar.set(y, getValue(year, 2) - 1, getValue(year, 0));
            String date = sdf.format(calendar.getTime());
            if (date.equals(year + new StringBuilder(year).reverse())) {
                System.out.println(date);
            }
        }
    }

    private static int getValue(String year, int begin) {
        return Integer.parseInt(new StringBuilder(year.substring(begin, begin + 2)).reverse().toString());
    }

|20011002 20100102 20111102 20200202 20211202 20300302 20400402 20500502 20600602 20700702 20800802 20900902| | |-----|--| | | |

你可能感兴趣的:(本世纪,巧合的年月日)