java中日期字符中首位为0去掉

时间:2021-10-22 18:10:37
public class Test {
 public static void main(String[] args) {
String time="16月12日";
//00 01 10 
String firstMonth3=time.substring(0, 1);
String firstDay3=time.substring(3, 4);
String a3="";
String b3="";
String c3="";
//01
if("0".equals(firstMonth3)&&!"0".equals(firstDay3)){
a3=time.substring(1,6);
  }
//00
if("0".equals(firstMonth3)&&"0".equals(firstDay3)){
a3=time.substring(1,3);
b3=time.substring(4,6);
  }
//10
if(!"0".equals(firstMonth3)&&"0".equals(firstDay3)){
a3=time.substring(0,3);
b3=time.substring(4,6);
  }
//11
if(!"0".equals(firstMonth3)&&!"0".equals(firstDay3)){
       a3=time.substring(0, 6);  
 }

    System.out.println(a3+b3+c3);
    
}
}