zoukankan      html  css  js  c++  java
  • 显示本月日历demo

    import java.text.DateFormatSymbols;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    
    public class TestCalendar {
    public static void main(String[] args) {
    	GregorianCalendar now=new GregorianCalendar();
    	int month=now.get(Calendar.MONTH);
    	int today=now.get(Calendar.DAY_OF_MONTH);
    	int intent=0;
    	now.set(Calendar.DAY_OF_MONTH, 1);
    	int week=now.get(Calendar.DAY_OF_WEEK);
    	int firstDayOfWeek=now.getFirstDayOfWeek();
    	while(firstDayOfWeek!=week){
    		++intent;
    		now.add(Calendar.DAY_OF_MONTH, -1);
    		week=now.get(Calendar.DAY_OF_WEEK);
    	}
    	String[] weekdayName=new DateFormatSymbols().getShortWeekdays();
    	do{
    		System.out.printf("%4s",weekdayName[week]);
    		now.add(Calendar.DAY_OF_MONTH, 1);
    		week=now.get(Calendar.DAY_OF_WEEK);
    	}while(week!=firstDayOfWeek);
    	System.out.println();
    	for(int i=0;i<intent;i++){
    		System.out.println("    ");
    	}
    	now.set(Calendar.DAY_OF_MONTH, 1);
    	week=now.get(Calendar.DAY_OF_WEEK);
    	int day=now.get(Calendar.DAY_OF_MONTH);
    	do{
    		System.out.printf("%4s", day);
    		if(today==day){
    			System.out.print("*");
    		}else {
    			System.out.print(" ");
    		}
    		now.add(Calendar.DAY_OF_MONTH, 1);
    		week=now.get(Calendar.DAY_OF_WEEK);
    		day=now.get(Calendar.DAY_OF_MONTH);
    		if(week==firstDayOfWeek){
    			System.out.println();
    		}
    	}while(month==now.get(Calendar.MONTH));
    	if(week!=firstDayOfWeek){
    		System.out.println();
    	}
    }
    }
    

      

  • 相关阅读:
    【杭电】[4857]逃生
    【杭电】[2647]Reward
    【杭电】[1285]确定比赛名次
    【杭电】[1251]统计难题
    OJ系统上线——OJ.BoilTask.com
    【郑轻】[1893]985的数学难题
    【郑轻】[1900]985的“树”难题
    【郑轻】[1898]985的数字难题
    HDU 1850———nim博弈
    HDU 2188------巴什博弈
  • 原文地址:https://www.cnblogs.com/ipetergo/p/6860991.html
Copyright © 2011-2022 走看看