How to add minutes to my Date

后端 未结 12 1268
长发绾君心
长发绾君心 2020-11-30 22:11

I have this date object:

SimpleDateFormat df = new SimpleDateFormat(\"yyyy-mm-dd HH:mm\");
Date d1 = df.parse(interviewList.get(37).getTime());
12条回答
  •  借酒劲吻你
    2020-11-30 22:34

    In order to avoid any dependency you can use java.util.Calendar as follow:

        Calendar now = Calendar.getInstance();
        now.add(Calendar.MINUTE, 10);
        Date teenMinutesFromNow = now.getTime();
    

    In Java 8 we have new API:

        LocalDateTime dateTime = LocalDateTime.now().plus(Duration.of(10, ChronoUnit.MINUTES));
        Date tmfn = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
    

提交回复
热议问题