java获取过去时间

    Calendar c = Calendar.getInstance();
     
    //过去七天
    c.setTime(new Date());
    c.add(Calendar.DATE, - 7);
    Date d = c.getTime();
     
    //过去一月
    c.setTime(new Date());
    c.add(Calendar.MONTH, -1);
    Date m = c.getTime();
     
    //过去三个月
    c.setTime(new Date());
    c.add(Calendar.MONTH, -3);
    Date m3 = c.getTime();
     
    //过去一年
    c.setTime(new Date());
    c.add(Calendar.YEAR, -1);
    Date y = c.getTime();

你可能感兴趣的:(JAVA,JAVA)