How to convert “Mon Jun 18 00:00:00 IST 2012” to 18/06/2012?

后端 未结 4 1881
北海茫月
北海茫月 2020-11-27 04:34

I have a value like the following Mon Jun 18 00:00:00 IST 2012 and I want to convert this to 18/06/2012

How to convert this?

I tri

4条回答
  •  失恋的感觉
    2020-11-27 05:24

    Just need to add: new SimpleDateFormat("bla bla bla", Locale.US)

    public static void main(String[] args) throws ParseException {
        java.util.Date fecha = new java.util.Date("Mon Dec 15 00:00:00 CST 2014");
        DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.US);
        Date date;
        date = (Date)formatter.parse(fecha.toString());
        System.out.println(date);        
    
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        String formatedDate = cal.get(Calendar.DATE) + "/" + 
                (cal.get(Calendar.MONTH) + 1) + 
                "/" +         cal.get(Calendar.YEAR);
        System.out.println("formatedDate : " + formatedDate);
    }
    

提交回复
热议问题