package com.aming.Date; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Scanner; public class TestViewDate { public static void main(String args[]){ System.out.println("请输入一个指定的日期(2015-08-22):"); Scanner scan = new Scanner(System.in); String inDate = scan.nextLine(); //String inDate = "2016-08-20"; //Date date = new Date(); DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = format.parse(inDate); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } Calendar c = new GregorianCalendar(); c.setTime(date); int tody = c.get(Calendar.DATE); c.set(Calendar.DATE,1); int week = c.get(Calendar.DAY_OF_WEEK); int maxDay = c.getActualMaximum(Calendar.DATE); //System.out.println(maxDay); //System.out.println(week); System.out.println("日\t"+"一\t"+"二\t"+"三\t"+"四\t"+"五\t"+"六"); for(int i =1;i<=maxDay+week-1;i++){ if(i<week){ System.out.print("\t"); }else{ if(tody == i-week+1){ //System.out.print("*"); System.out.print(i-week+1+"*\t"); }else{ System.out.print(i-week+1+"\t"); } } if(i%7==0) { System.out.println(); } } } }
时间: 2024-10-23 14:08:48