I am working with the Java Calendar class for android however I am getting some unexpected behaviour.
When I test the following code it gives me the desired results:
Calendar cal = Calendar.getInstance();
cal.getTimeInMillis() - System.currentTimeMillis(); // returns 0 indicating that they are synced
However when I change the values of the Calendar instance, it seems that it no longer returns the correct value for getTimeMillis.
For example:
// Current time : 1:56pm
cal.set(Calendar.HOUR, 13);
cal.set(Calendar.MINUTE, 0);
cal.getTimeInMillis(); // returns 1411448454463
System.currentTimeMillis(); // returns 1411407834463
cal.getTimeInMillis() - System.currentTimeMillis(); // returns 40620000
As you can see cal.getTimeInMillis()
returns a number larger than System.currentTimeMillis()
even though the time should be earlier (1:00pm vs 1:56pm).
Any help would be greatly appreciated!