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

后端 未结 4 1883
北海茫月
北海茫月 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:06

    I hope following program will solve your problem

    String dateStr = "Mon Jun 18 00:00:00 IST 2012";
    DateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy");
    Date date = (Date)formatter.parse(dateStr);
    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);    
    

提交回复
热议问题