如何在swing(Core Java)中将dd-mmm-yyyy格式转换为dd-mm-yyyy格式?

Ama*_*ngh 0 java date

转换dd-mmm-yyyydd-mm-yyyy格式。

String dateofbirth = ((JTextField) dobcalender.getDateEditor().getUiComponent()).getText();//date from jcalender

SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy");
Run Code Online (Sandbox Code Playgroud)

尝试了以下代码:

System.out.println(myFormat.format(myFormat.parse(dateofbirth)));
myFormat.format(myFormat.parse(dateofbirth));
Run Code Online (Sandbox Code Playgroud)

显示错误parseexception

Aru*_*M N 5

基于格式 “ 2019年2月24日”

 SimpleDateFormat from=new SimpleDateFormat("dd MMM yyyy");
 SimpleDateFormat to=new SimpleDateFormat("dd-MM-yyyy");
 Date frm=from.parse("24 Feb 2019");
 System.out.println(frm);//Sun Feb 24 00:00:00 IST 2019
 System.out.println(to.format(frm));//24-02-2019
Run Code Online (Sandbox Code Playgroud)