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?
As we can see from the documentation, it's because
mm
is for minutes, not months.mm
represents minutes, so when you usemm
, it will print minutes instead of month.While
MM
represents months.Read more about
Time Patterns