0

Hello I think I have a very simple question but i'm having trouble figuring it out.

I Got the Date and Time In Android using this code

String currentDateTimeString = DateFormat.getDateInstance().format(new Date());

It gave me back this value

Apr 21, 2016 9:30:16 PM

how do I compare using to dates with that value so if I want to see if

Apr 21, 2016 9:30:16 PM

is newer or older than

Apr 21, 2016 9:35:16 PM

How would I check that Thanks

Attempt One

I Tried This

DateFormat format = new SimpleDateFormat("MM-dd-yyyy", Locale.ENGLISH);
            Date fileDate = format.parse(date1);

DateFormat format2 = new SimpleDateFormat("MM-dd-yyyy", Locale.ENGLISH);
            Date metaDate = format.parse(date2);

this the value for date 1 and 2 being

Apr 21, 2016 9:35:16 PM

But it threw a parse exception. I must use that value above so What do I Need to do so it doesn't break the code when it tries to parse the date

Jordan
  • 407
  • 5
  • 20

1 Answers1

0

The easiest way is to use Date.before(), rather than comparing the strings. In fact its easier to convert the string back into a date than use the strings.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127