Using GregorianCalendar with SimpleDateFormat

后端 未结 5 1932
渐次进展
渐次进展 2020-12-03 04:45

So, I\'ve been racking my brain over this (should-be) simple exercise to make the program turn a date string into a GregorianCalendar object, format it, and ret

5条回答
  •  醉梦人生
    2020-12-03 05:10

    Why such complications?

    public static GregorianCalendar convertFromDMY(String dd_mm_yy) throws ParseException 
    {
        SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM-yyyy");
        Date date = fmt.parse(dd_mm_yy);
        GregorianCalendar cal = GregorianCalendar.getInstance();
        cal.setTime(date);
        return cal;
    }
    

提交回复
热议问题