修改特定的时间

    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    /**
     * @Description:  修改特定的时间
     * @param:
     * @date: 2020/1/16 22:02
     */
    @Test
    public void test01(){
        Date date = new Date();
        try {
            date = sdf.parse("1990-11-9 6:32:25");
        } catch (ParseException e) {
            log.info("转换失败:{}",e.getMessage());
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        System.out.println(sdf.format(calendar.getTime()).trim()); // 1990-11-09 06:32:25
        calendar.add(Calendar.YEAR,-1);
        calendar.add(Calendar.MONTH,-2);
        Date newTime = calendar.getTime();
        String stringDate = sdf.format(newTime).trim();
        System.out.println(stringDate);  // 1989-09-09 06:32:25
    }

你可能感兴趣的:(修改特定的时间)