I create a date and then format is like this:
Example 1:
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
String currentDate = sdf.format(new Date());
What I would like to do is check if this date is before another date (also formatted the same way). How would I go about doing this?
Example 2:
Also, how would I check whether one of these is before another:
long setForLong = System.currentTimeMillis() + (totalTime*1000);
String display = (String) DateFormat.format("HH:mm:ss dd/MM/yyyy", setForLong);
EDIT:
I think more detail is needed. I create a date in two different ways for two different uses. The first use just formats the current date into a string so it is readable for the user. In the second case, I am using a date in the future with System.currentTimeMillis
and adding on a long
. Both result in a string.
Both methods format the date in exactly the same way, and I set the strings into a TextView
. Later, I need to compare these dates. I do not have the original data/date/etc, only these strings. Becasue they are formatted in the same way, I though it would be easy to compare them.
I have tried the if(String1.compareTo(String2) >0 )
method, but that does not work if the day is changed.
If you only have two
String
objects that are dates available to you. You will need to process them in something, either in your own comparator class or in another object. In this case, since these are already formatted into dates, you can just createDate
objects and compare using the methods previously posted. Something like this: