Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Calendar; public class Main { private static int dateCompareTo(Calendar calEnd, Calendar calStart) { if (calEnd.get(Calendar.DAY_OF_YEAR) == calStart.get(Calendar.DAY_OF_YEAR)) { if (calEnd.get(Calendar.YEAR) == calStart.get(Calendar.YEAR)) { return 0; } else { if (calEnd.get(Calendar.YEAR) > calStart.get(Calendar.YEAR)) { return 1; } else { return -1; } } } else { if (calEnd.get(Calendar.YEAR) == calStart.get(Calendar.YEAR)) { if (calEnd.get(Calendar.DAY_OF_YEAR) > calStart.get(Calendar.DAY_OF_YEAR)) { return 1; } else { return -1; } } else if (calEnd.get(Calendar.YEAR) > calStart.get(Calendar.YEAR)) { return 1; } else { return -1; } } } }