I'm trying to write a Java script that computes the time difference between the current date and the last updated time stored on our Parse backend. Can anyone help me spot the bug in my code? You'd think this isn't so bad, but I've looked on Stack Overflow for hours to no avail.
//Create a date formatter.
SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'LLL'Z'");
//Create a date object for today's date.
Date currentDate=new Date();
//Create a string for the date from parse.
String parseTime = singleClaim.getString("updatedAt");
//Create a string for the current date.
String currentTime=currentDate.toString();
//Initialize the date object for the updatedAt time on Parse.
Date parseDate = null;
//Initialize the date object for the current time.
Date FormattedCurrentDate = null;
try {
//Here, we convert the parseTime string into a date object and format it.
parseDate = formatter.parse(parseTime);
//Here, we convert the currentTime string into a date object and format it.
FormattedCurrentDate = formatter.parse(currentTime);
}
catch (Exception e) {
e.printStackTrace();
}
//Get the time difference from the current date versus the date on Parse.
long difference = FormattedCurrentDate.getTime()-parseDate.getTime();