Skip to content

Debug simple java code related to Calendar Date GMT

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class Test {

    public static void main(String[] args) throws ParseException {

        Calendar dateFromNet = strToCal("11-MAR-2004", "dd-MMM-yyyy");
        Calendar IEndTime = strToCal("20-05-2004", "dd-mm-yyyy");

        if (dateFromNet.after(IEndTime) ) {


            System.out.println("not true: 11-MAR-2004(11-3-2004) > 20-05-2004 ");


    private static Calendar strToCal(String date, String format) throws ParseException {
        SimpleDateFormat input = new SimpleDateFormat(format);

        Date d = (Date) input.parse(date);
        Calendar c = Calendar.getInstance();
        return c;

This test shows

dateFromNet.after(IEndTime) == true

i.e. 11-03-2004 is after 20-05-2004

What have I done wrong?


Calendar IEndTime = strToCal("20-05-2004", "dd-mm-yyyy");

mm is for milliseconds; make those capitol M, like this:

Calendar IEndTime = strToCal("20-05-2004", "dd-MM-yyyy");