In layout.xml for a java swing project, the ddMMMyyyy format attaches 00 to year if date entered

StackOverflow https://stackoverflow.com/questions/21326294

  •  02-10-2022
  •  | 
  •  

Question

If 12-Jan-14 entered into the date field manually, it becomes 12-Jan-0014. Auto tab is "1:9".

Was it helpful?

Solution

SimpleDateFormat sdf=new SimpleDateFormat("ddMMMyyyy");

If you use this format to format your dates it will gives you date like 12-Jan-0014

If you want to display date as 12-Jan-14 then use this:

SimpleDateFormat sdf=new SimpleDateFormat("ddMMMyy");

Example:

String startdateString = "12-Jan-2014";
SimpleDateFormat fromUser2 = new SimpleDateFormat("dd-MMM-yy");
startdateString = fromUser2.format(fromUser2.parse(startdateString));
System.out.println(startdateString);

OUTPUT

12-Jan-14
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top