Java tutorial
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; public class Main { public static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static boolean isLeapYear(String time) { return isLeapYear(string2Date(time, DEFAULT_PATTERN)); } public static boolean isLeapYear(String time, String pattern) { return isLeapYear(string2Date(time, pattern)); } public static boolean isLeapYear(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); int year = cal.get(Calendar.YEAR); return isLeapYear(year); } public static boolean isLeapYear(long millis) { return isLeapYear(millis2Date(millis)); } public static boolean isLeapYear(int year) { return year % 4 == 0 && year % 100 != 0 || year % 400 == 0; } public static Date string2Date(String time) { return string2Date(time, DEFAULT_PATTERN); } public static Date string2Date(String time, String pattern) { return new Date(string2Millis(time, pattern)); } public static Date millis2Date(long millis) { return new Date(millis); } public static long string2Millis(String time) { return string2Millis(time, DEFAULT_PATTERN); } public static long string2Millis(String time, String pattern) { try { return new SimpleDateFormat(pattern, Locale.getDefault()).parse(time).getTime(); } catch (ParseException e) { e.printStackTrace(); } return -1; } }