private String simplify(String date){
int index1 =date.indexOf("-");
int index2 =date.lastIndexOf("-");
int month;
int day;
int year=Integer.parseInt(date.substring(0,index1));
if(date.substring(index1+1,index1+2)=="0"){
month=Integer.parseInt(date.substring(index1+2,index1+3));
}else {
month=Integer.parseInt(date.substring(index1+1,index1+3));
}
if(date.substring(index2+1,index2+2)=="0"){
day=Integer.parseInt(date.substring(index2+2,index2+3));
}else{
day=Integer.parseInt(date.substring(index2+1,index2+3));
}
String date1=(year+"-"+month+"-"+day)+"";
return date1;
}
转自:https://blog.csdn.net/qq_28670711/article/details/78967708