A search API is returning date in String format,I want to compare that date with current date and do something. I created a date object and parsed it but still getting error when I do the compare.
Calendar currentDate = Calendar.getInstance();
long dateNow = currentDate.getTimeInMillis();
String eventDate = meta.getString("startDate"); //This is the string API returns
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss.SSS");
Date date = formatter.parse(eventDate);
long modifiedDate= date.getTime();
if (dateNow.compareTo(modifiedDate)>0) {
//Do Something
}
Error I get is :
Cannot invoke compareTo(long) on the primitive type long
Thanks.
When comparing primitive
longs just use a vanilla comparison operator:This is not recommended, but if you want to use
compareTo, first convert toLong: