/**
     * 当前日期加上指定天数后
     * @param num 为增加的天数
     * @return
     */
    public static String plusDay(int num){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar ca = Calendar.getInstance();
        ca.add(Calendar.DATE, num);
        return format.format(ca.getTime());
    }
    
    

 

    /**
     * 给定日期加上指定天数后
     * @param date
     * @param day
     * @return
     */
    public static String addDate(Date date,long day) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long time = date.getTime();
        day = day*24*60*60*1000;
        time+=day;
        return format.format(new Date(time));
    }
    

 

    
    @Test
    public void start(){
        
        Boolean flag = true;
        Date d = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            d = format.parse("2020-02-20 10:100syut:1");
        } catch (ParseException e) {
            flag = false;
            System.out.println("转换错误!");
        }
        
        if(flag)System.out.println(Num_test.addDate(d,5));
        
    }
    

 

相关文章:

  • 2021-07-07
  • 2022-12-23
  • 2021-05-25
  • 2021-08-18
  • 2022-12-23
  • 2021-11-04
  • 2022-01-27
  • 2021-11-14
猜你喜欢
  • 2022-01-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-07-31
  • 2021-05-17
相关资源
相似解决方案