-5

I have a string with date and time in this format:

9 Oct 2014 07:09:17 GMT

Is there an easy way to convert this string into a comparable object, to compare with the current date, or I'll have to implement a comparison processing the string?

user3782779
  • 1,669
  • 3
  • 22
  • 36

2 Answers2

0
 SimpleDateFormat formatter = new SimpleDateFormat("d MMM yyyy kk:mm:ss zzz");  
 String str1 = "9 Oct 2014 07:09:17 GMT";
 Date date1 = formatter.parse(str1);
user3782779
  • 1,669
  • 3
  • 22
  • 36
-1

Try using this:

try{
     SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");  
     String str1 = "your first date";
     Date date1 = formatter.parse(str1);

     String str2 = "Your second date";
     Date date2 = formatter.parse(str2);

     if (date1.compareTo(date2)<0){
         System.out.println("date2 is Greater than my date1");           
     }
  }catch (ParseException e1){
       e1.printStackTrace();
  }
akash
  • 22,664
  • 11
  • 59
  • 87
Himanshu Agarwal
  • 4,623
  • 5
  • 35
  • 49