转换dd-mmm-yyyy为dd-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
基于格式 “ 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)
| 归档时间: |
|
| 查看次数: |
104 次 |
| 最近记录: |