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

      

  • 相关阅读:
    axis2依赖的其他jar, 版本不是最新的
    mysql: 安装后的目录结构
    视图的使用
    索引
    递归查询 start with connect by prior
    oracle创建表
    C#中 ??、 ?、 ?: 、?.、?[ ] 和$
    C#关键字static、virtual和abstract笔记
    js调用后台,后台调用前台等方法总结
    java基础序列化
  • 原文地址:https://www.cnblogs.com/ipetergo/p/6860991.html
Copyright © 2011-2022 走看看