HashMap hm = new HashMap();
        hm.put("January", "Jan");
        hm.put("Febraury", "Feb");
        hm.put("March", "Mar");
        hm.put("April", "Apr");
        hm.put("May", "May");
        hm.put("June", "Jun");
        hm.put("July", "Jul");
        hm.put("August", "Aug");
        hm.put("September", "Sep");
        hm.put("October", "Oct");
        hm.put("November", "Nov");
        hm.put("December", "Dec");
        for (int k = 1; k <= 12; k++) {
            if (Time.contains("January")) {

            }
        }


如果时间包含2013年9月25日这样的时间,那么预期的输出是2013年9月25日。我要怎么做,谢谢你

最佳答案

尝试以下。

 public static void main(String[] args) throws Exception {

            String time = "September 25,2013";
            HashMap<String,String> hm = new HashMap<String, String>();
            hm.put("January", "Jan");
            hm.put("Febraury", "Feb");
            hm.put("March", "Mar");
            hm.put("April", "Apr");
            hm.put("May", "May");
            hm.put("June", "Jun");
            hm.put("July", "Jul");
            hm.put("August", "Aug");
            hm.put("September", "Sep");
            hm.put("October", "Oct");
            hm.put("November", "Nov");
            hm.put("December", "Dec");
            for (String key : hm.keySet()) {
                if (time.contains(key)) {
                    String newTime = time.replace(key, hm.get(key));
                    System.out.println(newTime);
                }
            }
        }

10-07 20:09