how to add number of days to the date given in a jtextfield with string data type

后端 未结 3 1336
梦毁少年i
梦毁少年i 2021-01-21 08:42

Good Day . I just wanna ask about adding days in a given date. I have a jtexfield (txtStart) and another jtexfield(txtExpiry). I need to display in txtExpiry the date after 102

3条回答
  •  轮回少年
    2021-01-21 08:52

    Use

    yyyy-MM-dd
    

    Note: Capital MM

    See : SimpleDateFormat

    Now, once you have the date instance you could use Calendar to do the days arithmetic

    Calendar cal = Calendar.getInstance();
    cal.setTime(parsedDate);
    cal.add(Calendar.DATE, 102);
    String expDateString = dateFormatter.format(cal.getTime());
    

提交回复
热议问题