 <pre><code>Date date = new Date(); String str="2013-08-23"; Date date=new SimpleDateFormat("yyyy-MM-dd").parse(str); Calendar cal = Calendar.getInstance(); cal.setTime(date); Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); if(cal.get(Calendar.YEAR) == cal1.get(Calendar.YEAR)){ System.out.println("Years are equal"); } else{ System.out.println("Years not equal"); } if(cal.get(Calendar.MONTH) == cal1.get(Calendar.MONTH)){ System.out.println("Months are equal"); } else{ System.out.println("Months not equal"); } </code></pre>