java 获取某周前的礼拜一

package com.poi.examples;

import java.text.SimpleDateFormat;
import java.util.*;

public class PrevWeek {
	 public static void main(String[] args) {
	        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	        Date dt = prevWeek(new Date(), 7);
	        System.out.println(sdf.format(dt));
	    }
	 
	    public static Date prevWeek(Date dt, int week) {
	        Calendar cal = Calendar.getInstance();
	        cal.setTime(dt);
	        cal.add(Calendar.DAY_OF_MONTH, -week * 7 + (9-cal.get(Calendar.DAY_OF_WEEK)));
	        return cal.getTime();
	    }
}
 

你可能感兴趣的:(java)