java获取某个时间的上周一和周日
展开全部
mport java.text.SimpleDateFormat;
import java.util.Calendar;
public class Test{
public static void main(String args[]){
Calendar cal = Calendar.getInstance();
//n为推迟的周数,1本周,-1向前推迟一周,2下周,依次类推
int n = 2;
String monday;
cal.add(Calendar.DATE, n*7);
//想周几,这里就传几Calendar.MONDAY(TUESDAY...)
cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
monday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
System.out.println(monday);
}
}
import java.util.Calendar;
public class Test{
public static void main(String args[]){
Calendar cal = Calendar.getInstance();
//n为推迟的周数,1本周,-1向前推迟一周,2下周,依次类推
int n = 2;
String monday;
cal.add(Calendar.DATE, n*7);
//想周几,这里就传几Calendar.MONDAY(TUESDAY...)
cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
monday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
System.out.println(monday);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询