How to format Joda-Time DateTime to only mm/dd/yyyy?

前端 未结 9 1255
挽巷
挽巷 2020-11-29 15:52

I have a string \"11/15/2013 08:00:00\", I want to format it to \"11/15/2013\", what is the correct DateTimeFormatter pattern?

9条回答
  •  醉话见心
    2020-11-29 16:12

    This works

    String x = "22/06/2012";
    String y = "25/10/2014";
    
    String datestart = x;
    String datestop = y;
    
    //DateTimeFormatter format = DateTimeFormat.forPattern("dd/mm/yyyy");
    SimpleDateFormat  format = new SimpleDateFormat("dd/mm/yyyy");
    
    Date d1 = null;
    Date d2 = null;
    
    try {
        d1 =  format.parse(datestart);
        d2 = format.parse(datestop);
    
        DateTime dt1 = new DateTime(d1);
        DateTime dt2 = new DateTime(d2);
    
        //Period
        period = new Period (dt1,dt2);
    
        //calculate days
        int days = Days.daysBetween(dt1, dt2).getDays();
    
    
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    

提交回复
热议问题