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();
    	}
    }
    }
    

      

  • 相关阅读:
    Canvas中的save方法和restore方法
    python之函数默认参数的坑
    python之函数名的应用
    python之golbal/nonlocal
    python之*的魔性用法
    python之函数的传参形参的第三种动态参数*args和**kwargs
    python之道09
    python之函数的初识
    python之道08
    python之99乘法表
  • 原文地址:https://www.cnblogs.com/ipetergo/p/6860991.html
Copyright © 2011-2022 走看看