code for converting the date in String format to Date format..and compare those two Dates in android..

String date=(String) android.text.format.DateFormat.format("MM/dd/yy", new java.util.Date());
        System.out.println("---date----"+date);
        String Date1 = "11-01-2011";
        String Date2 = "12-01-2011";
        ////String formatString = "MM-dd-yyyy"; // for example
        SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy");
        Date date1=null;
        try {
            date1 = df.parse(Date1);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Date date2=null;
        try {
            date2 = df.parse(Date2);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (date1.before(date2))
        System.out.println("first date is (smaller)earlier");
        else
        System.out.println("second date is (smaller)earlier");   

Comments

Popular posts from this blog

Custom Dialog with no title and full screen in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard

Best working code to set Date limits on Date Picker Dialog,in Android