Java tutorial
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static boolean isCardExpired(String expiry, Date referenceDate) { boolean expired = false; int monthExpiry = Integer.parseInt(expiry.substring(0, 2)); int yearExpiry = 2000 + Integer.parseInt(expiry.substring(2, 4)); Calendar c = Calendar.getInstance(); c.setTime(referenceDate); int monthRef = c.get(Calendar.MONTH) + 1; // months indexed from 0 in java int yearRef = c.get(Calendar.YEAR); if (yearExpiry < yearRef) { expired = true; } else if (yearExpiry == yearRef && monthExpiry < monthRef) { expired = true; } return expired; } }