首页 > 其他 > 详细

calendar 示例

时间:2016-08-01 00:23:27      阅读:278      评论:0      收藏:0      [点我收藏+]
package unit5;

import java.text.DateFormatSymbols;

public class MyMonth {
    private  int month;
    private int start_of_week;
    private int days_in_month;
    public static String [] weekdayNames=new DateFormatSymbols().getShortWeekdays();
    private String[][] data = new String[7][8];
    public MyMonth(int m,int s,int d){
        month=m;
        days_in_month=d;
        start_of_week=s;
    
        for(int j=1;j<8;j++){
            data[0][j]=new String(MyMonth.weekdayNames[j]);
        }
        
        int days=1,day_of_week=start_of_week,r=1;
        do{
            data[r][day_of_week]=String.valueOf(days);
            days++;
            day_of_week++;
            if(day_of_week==8){
                day_of_week=1;
                r++;
            }
                
        }while(days<=days_in_month);
    }
    public void display(){
        System.out.println("\t\t\t"+(month+1)+"month");
        System.out.println("==================================================");
        for(int i=0;i<7;i++){
            for(int j=1;j<8;j++){
                if(data[i][j]==null) System.out.print("\t");
                else System.out.print(data[i][j]+"\t");
            }
            System.out.println();
        }
        System.out.println("==================================================");
    }
    public int getMonth(){return month+1;}
    public int getDaysInMoth(){return days_in_month;}
    public String[][] getData(){return data;}
    
}

 

 

package unit5;
import java.awt.CardLayout;
import java.util.*;

public class MyCalendarTest {
    public static void main(String[] args) {
        Calendar d =Calendar.getInstance();
        Scanner keyin = new Scanner(System.in);
        System.out.println("please enter the year that you want to see:");
        int year = keyin.nextInt();
        d.set(Calendar.YEAR,year);
        MyMonth[] mymonth=new MyMonth[12];
        for(int i=0;i<Calendar.DECEMBER;i++){
            d.set(Calendar.MONTH,i);
            d.set(Calendar.DAY_OF_MONTH,1);
            mymonth[i]=new MyMonth(i,d.get(Calendar.DAY_OF_WEEK),d.getActualMaximum(Calendar.DAY_OF_MONTH));
        }
        //mymonth[0].display();
        for(int i=0;i<=Calendar.DECEMBER;i+=2){
         displyTwoMonth(mymonth[0],mymonth[1]);
        }
        
    }
    public static void displyTwoMonth(MyMonth mon1,MyMonth mon2){
        System.out.print("\t\t\t"+mon1.getMonth()+" month ");
        System.out.println("\t\t\t\t\t\t"+mon2.getMonth()+" moth ");
        System.out.print("==========================================");
        System.out.println("\t\t\t=============================================");
        String [][]d1=mon1.getData();
        String [][]d2 = mon2.getData();
        for(int i=0;i<7;i++){
            for(int j=0;j<8;j++)
            {
                if(d1[i][j]==null) System.out.print("\t");
                else System.out.print(d1[i][j]+"\t");
            }
            for(int j=0;j<8;j++)
            {
                if(d1[i][j]==null) System.out.print("\t");
                else System.out.print(d2[i][j]+"\t");
            }
            System.out.println();
        }
        
        System.out.print("==========================================");
        System.out.println("=============================================");
        
        
        
        
    }

}

 

calendar 示例

原文:http://www.cnblogs.com/superxuezhazha/p/5724308.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!