Skip to content
Advertisement

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

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?

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement