I have following piece of code, which is just calculating time in milliseconds for their respective date objects
public static void main(String... args) throws ParseException
{
SimpleDateFormat APIformatter = new SimpleDateFormat("MM-dd-yyyy HH:MM");
Calendar calendar = Calendar.getInstance();
Date date = APIformatter.parse("01-23-2017 17:58:23");
calendar.setTime(date);
System.out.println(calendar.getTimeInMillis());
Calendar calendar2 = Calendar.getInstance();
Date date2 = APIformatter.parse("01-24-2017 11:55:54");
calendar2.setTime(date2);
System.out.println(calendar2.getTimeInMillis());
}
clearly date2
is recent than date
object, hence I expect that the value returned by getTimeInMillis()
will be greater for date2
as compared to date1
.
However that is not the case
System.out.println(calendar.getTimeInMillis()); returning me 1634988600000
and
System.out.println(calendar2.getTimeInMillis()); returning me 1627104600000
clearly date > date2
in returned values.
Am I missing something here?