I am trying to figure out how to calculate the time difference between two dates in milliseconds.
I found this piece of code (https://stackoverflow.com/a/39129969/8921111) from another cn1 question, but when I send an Android build, I receive error for the method set().
error: method set in class Calendar cannot be applied to given types;
Here is the code:
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
try {
java.util.Calendar now = java.util.Calendar.getInstance();
now.set(now.get(java.util.Calendar.YEAR), now.get(java.util.Calendar.MONTH), now.get(java.util.Calendar.DATE), 0, 0, 0);
now.set(java.util.Calendar.MILLISECOND, 0);
java.util.Calendar otherDate = java.util.Calendar.getInstance();
otherDate.setTime(dateFormat.parse("6/28/2021"));
otherDate.set(otherDate.get(java.util.Calendar.YEAR), otherDate.get(java.util.Calendar.MONTH), otherDate.get(java.util.Calendar.DATE), 0, 0, 0);
otherDate.set(java.util.Calendar.MILLISECOND, 0);
long num =otherDate.getTime().getTime()- now.getTime().getTime();
Log.p("The long millis expiration is in "+ (long) (num));
} catch (ParseException ex) {
return -999999;
}
Will appreciate your help.