dd/mm/yyyy vs dd/MM/yyyy?

Tags: ,



SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        String date = sdf.format(new Date()); 
        System.out.println(date); 

Result is todays date i.e 23/03/2014

But when i do

 SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy"); 

result can be 23/05/2014, 23/05/2014, 23/06/2014 and son with each run of prgram. Why so?

Answer

It’s because mm is for minutes, not months. More in the documentation.



Source: stackoverflow