PrivateDate Getdatebytype (date date, Integer type) {Calendar Calendar=calendar.getinstance (); Calendar.settime (date); Switch(type) { Case1:/*daily newspaper*/ //Tomorrow's dateCalendar.add (Calendar.date, 1); Break; Case2:/*Weekly*/ //get the current date is the day of the week one intDayWeek =Calendar.get (Calendar.day_of_week); if(1 = =DayWeek) {Calendar.add (Calendar.day_of_month,-1); } //set one the first day of the week, according to the Chinese habit one weeks the first day is MondayCalendar.setfirstdayofweek (Calendar.monday); //get the current date is the day of the week one intDay =Calendar.get (Calendar.day_of_week); intFirst =Calendar.getfirstdayofweek (); //calculate dates for FridayCalendar.add (Calendar.day_of_week, First-day + 4); Break; Case3:/*Monthly Report*/ //get the maximum number of days of the month intDays =Calendar.getactualmaximum (Calendar.day_of_month); //set to create a new date, this date is the last day of this monthCalendar.set (Calendar.date, days); Break; default: Break; } returnCalendar.gettime (); }
Java gets tomorrow, the current week of Friday, and the last day of the current month based on the current time