import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Testdouhao { public static void main(String[] args) { int dayu=-7; for(int i=0;i>dayu;i--){ Date date=new Date();//取时间 Calendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.add(calendar.DATE,i);//把日期往后增加一天.整数往后推,负数往前移动 date=calendar.getTime(); //这个时间就是日期往后推一天的结果 // System.out.println(date); SimpleDateFormat sFormat=new SimpleDateFormat("yyyyMMdd"); if(getWeekOfDate(date).equals("星期六") ){ --dayu; }else if(getWeekOfDate(date).equals("星期日")){ --dayu; }else{ System.out.println(sFormat.format(date)); } } } public static String getWeekOfDate(Date dt) { String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; Calendar cal = Calendar.getInstance(); cal.setTime(dt); int w = cal.get(Calendar.DAY_OF_WEEK) - 1; if (w < 0) w = 0; return weekDays[w]; } }
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/10180.html