import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Scanner; /** * Created by ttc on 16-11-2. */ public class Main { public static void main(String[] args) throws ParseException, ParseException { // write your code here System.out.println("请输入日期 (格式yyyy-MM-dd) : "); Scanner scanner = new Scanner(System.in); String inputDate = scanner.nextLine(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date date = format.parse(inputDate); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.DATE,1); int sumDays = calendar.getActualMaximum(Calendar.DATE); System.out.println("日\t一\t二\t三\t四\t五\t六"); for(int i=1;i<calendar.get(Calendar.DAY_OF_WEEK);i++) { System.out.print("\t"); } for(int i=1;i<=sumDays;i++) { System.out.print(i+"\t"); if(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) { System.out.println(); } calendar.add(Calendar.DATE,1); } } }
日历
最新推荐文章于 2022-12-10 11:32:12 发布