要转换dd-mmm-yyyy
至dd-mm-yyyy
格式。
String dateofbirth = ((JTextField) dobcalender.getDateEditor().getUiComponent()).getText();//date from jcalender
SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy");
尝试了这些代码:
System.out.println(myFormat.format(myFormat.parse(dateofbirth)));
myFormat.format(myFormat.parse(dateofbirth));
显示错误解析异常
最佳答案
基于格式“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
关于java - 如何在swing(core java)中将dd-mmm-yyyy格式转换为dd-mm-yyyy格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57653165/