java中的日期转换
获取时间日期中有英文单词的月份的时间转换
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 }