How to add days into the date in android

前端 未结 10 1141
眼角桃花
眼角桃花 2020-12-01 12:07

In my database I am getting start date like 2011-11-30(yyyy/mm/dd)format.and duration date like 40 days.How can i calculate the days and get new date format of mm/dd/yyyy.

10条回答
  •  情歌与酒
    2020-12-01 12:41

    Just Simple copy this method pass data

    public static String ConvertToDate(String dateString,String inputFormater ,String outputFormater) {
            String outputText = "" ;
            try {
                SimpleDateFormat inputFormat = new SimpleDateFormat(inputFormater);
                SimpleDateFormat outputFormat = new SimpleDateFormat(outputFormater);
                Date parsed = null;
                parsed = inputFormat.parse(dateString);
                outputText = outputFormat.format(parsed);
    
            Log.d(TAG, "  msg : " + outputText);
            } catch (ParseException e) {
                e.printStackTrace();
                Log.e(TAG, "ERROR : " + e.getMessage());
            }
            return outputText;
        } 
    

    And call it like

     public static String INPUTE_JSON_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
     public static String FORMAT_FOR_JOB_APPLIED = "MMM dd, yyyy";
     String date ="2017-10-29";
     ConvertToDate(date ,DateUtils.INPUTE_JSON_DATE_FORMAT ,DateUtils.FORMAT_FOR_JOB_APPLIED);  
    

    You can put any format you want in your cituation

    ConvertToDate("2011-11-30","yyyy/mm/dd" ,"mm/dd/yyyy");  
    

提交回复
热议问题