1 String time = "Sept 7, 2017";//能夠是完整英文單詞月份 2 SimpleDateFormat format = new SimpleDateFormat("MMMdd,yyyy",Locale.UK); 3 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");//最終獲取的時間格式,根據需求轉換 4 String times = ""; 5 Date date = format.parse(time); 6 times = simpleDateFormat.format(date);
1 /** 2 * 其餘格式的時間轉換成完整英文單詞月份的時間格式 3 */ 4 public static void getBackTime(){ 5 String time = "20181230"; 6 SimpleDateFormat format = new SimpleDateFormat("MMMM dd,yyyy",Locale.UK); 7 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); 8 String times = ""; 9 10 try { 11 Date date = simpleDateFormat.parse(time); 12 times = format.format(date); 13 } catch (ParseException e) { 14 // TODO Auto-generated catch block 15 e.printStackTrace(); 16 } 17 System.out.println(times); 18 }
1 /** 2 * 字符串截取中英文字段 3 * @throws Exception 4 */ 5 public static void getStringEnCn() throws Exception{ 6 String reg = "[^\u4e00-\u9fa5]"; 7 String string = "澳大利亞昆士蘭州南布里斯本雷蒙德特雷斯,郵編4101 RAYMOND TERRACE, SOUTH BRISBANE, QLD 4101, AUSTRALIA"; 8 String address = string;//********************************************註冊地址 9 String cnnAdress = "";//*********************************************************************註冊中文地址 10 String ennAdress = "";//*********************************************************************註冊英文地址 11 cnnAdress = address.replaceAll(reg, ""); 12 if(!cnnAdress.equals("") && !cnnAdress.equals(null)){ 13 String strA = cnnAdress.substring(cnnAdress.length() - 1); 14 int qAdress = address.lastIndexOf(strA); 15 String yb = ""; 16 String kh = ""; 17 if(cnnAdress.length() > 3){ 18 //截取最後兩個漢字 19 yb = address.substring(qAdress-1, qAdress+1); 20 //截取郵編前面的字符 21 kh = address.substring(qAdress-2, qAdress-1); 22 } 23 //截取漢字字符串最後一個漢字後面的第一個字符 24 String zwfh = address.substring(qAdress+1, qAdress+2); 25 byte[] cnbyte = zwfh.getBytes("UTF-8"); 26 //截取漢字字符串最後一個漢字後面的第二個字符 27 String second = address.substring(qAdress+2, qAdress+3); 28 if(yb.equals("郵編")){//漢字最後爲郵編沒有冒號 29 if(zwfh.equals(":") || zwfh.equals(":")){////漢字最後爲郵編且冒號爲中文冒號 30 if(kh.equals("(") || kh.equals("(")){ 31 if(address.contains("日本")){ 32 cnnAdress = address.substring(0, qAdress + 11); 33 ennAdress = address.substring(qAdress + 11).toUpperCase(); 34 }else if((address.contains("美國"))){ 35 cnnAdress = address.substring(0, qAdress + 8); 36 ennAdress = address.substring(qAdress + 8).toUpperCase(); 37 }else if(address.contains("澳大利亞")){ 38 cnnAdress = address.substring(0, qAdress + 7); 39 ennAdress = address.substring(qAdress + 7).toUpperCase(); 40 }else{ 41 cnnAdress = address.substring(0, qAdress + 9); 42 ennAdress = address.substring(qAdress + 9).toUpperCase(); 43 } 44 }else{ 45 if(address.contains("日本")){ 46 cnnAdress = address.substring(0, qAdress + 10); 47 ennAdress = address.substring(qAdress + 10).toUpperCase(); 48 }else if((address.contains("美國"))){ 49 cnnAdress = address.substring(0, qAdress + 7); 50 ennAdress = address.substring(qAdress + 7).toUpperCase(); 51 }else if(address.contains("澳大利亞")){ 52 cnnAdress = address.substring(0, qAdress + 6); 53 ennAdress = address.substring(qAdress + 6).toUpperCase(); 54 }else{ 55 cnnAdress = address.substring(0, qAdress + 8); 56 ennAdress = address.substring(qAdress + 8).toUpperCase(); 57 } 58 } 59 }else{ 60 if(kh.equals("(") || kh.equals("(")){ 61 if(address.contains("日本")){ 62 cnnAdress = address.substring(0, qAdress + 11); 63 ennAdress = address.substring(qAdress + 11).toUpperCase(); 64 }else if((address.contains("美國"))){ 65 cnnAdress = address.substring(0, qAdress + 7); 66 ennAdress = address.substring(qAdress + 7).toUpperCase(); 67 }else if(address.contains("澳大利亞")){ 68 cnnAdress = address.substring(0, qAdress + 6); 69 ennAdress = address.substring(qAdress + 6).toUpperCase(); 70 }else{ 71 cnnAdress = address.substring(0, qAdress + 8); 72 ennAdress = address.substring(qAdress + 8).toUpperCase(); 73 } 74 }else{ 75 if(address.contains("日本")){ 76 cnnAdress = address.substring(0, qAdress + 10); 77 ennAdress = address.substring(qAdress + 10).toUpperCase(); 78 }else if((address.contains("美國"))){ 79 cnnAdress = address.substring(0, qAdress + 6); 80 ennAdress = address.substring(qAdress + 6).toUpperCase(); 81 }else if(address.contains("澳大利亞")){ 82 cnnAdress = address.substring(0, qAdress + 5); 83 ennAdress = address.substring(qAdress + 5).toUpperCase(); 84 }else{ 85 cnnAdress = address.substring(0, qAdress + 7); 86 ennAdress = address.substring(qAdress + 7).toUpperCase(); 87 } 88 } 89 } 90 }else{ 91 if(cnbyte.length < 3 && second.equals("-")){//漢字後面爲 6號9-1 形式地址格式 92 cnnAdress = address.substring(0, qAdress + 4); 93 ennAdress = address.substring(qAdress + 4).toUpperCase(); 94 }else if(cnbyte.length < 3 && !second.equals("-") && !zwfh.equals(")")){// 95 cnnAdress = address.substring(0, qAdress + 1); 96 ennAdress = address.substring(qAdress + 1).toUpperCase(); 97 }else if(zwfh.equals(")") || zwfh.equals(")")){ 98 cnnAdress = address.substring(0, qAdress + 2); 99 ennAdress = address.substring(qAdress + 2).toUpperCase(); 100 } 101 } 102 }else{ 103 ennAdress = address.toUpperCase(); 104 } 105 106 System.out.println("****************"+cnnAdress); 107 System.err.println("----------------"+ennAdress); 108 }