posts - 97,  comments - 93,  trackbacks - 0

          /**
           * 程序運(yùn)行當(dāng)年的日歷,程序運(yùn)行當(dāng)日以*號(hào)表示
           */

          import java.util.*;

          public class CalendarTest {
           public static void main(String[] args) {
            GregorianCalendar d = new GregorianCalendar();
            int year = d.get(Calendar.YEAR);
            int month = d.get(Calendar.MONTH);
            int today = d.get(Calendar.DAY_OF_YEAR);
            d.set(d.get(Calendar.YEAR),0,1);                  //設(shè)置為當(dāng)年1月1日(0表示1月)
            do {
             System.out.println(d.get(Calendar.MONTH) + 1 + "月");
             System.out.println("Sun Mon Tue Wed Thu Fri Sat"); //輸出月表頭
             month = d.get(Calendar.MONTH);                //取得月份    
             int weekday = d.get(Calendar.DAY_OF_WEEK);    //獲得當(dāng)月1號(hào),在一周中是星期幾
             for(int i = Calendar.SUNDAY; i < weekday; i++)//控制當(dāng)月1號(hào)的起始位置
              System.out.print("    ");
             do {
              weekday = d.get(Calendar.DAY_OF_WEEK);
              if (d.get(Calendar.DAY_OF_MONTH) < 10)    //如果日期小于10,多輸出一個(gè)空格,以便對(duì)齊
               System.out.print(" ");
              System.out.print(d.get(Calendar.DAY_OF_MONTH));//輸出日期
              if (today == d.get(Calendar.DAY_OF_YEAR)) //如果是當(dāng)日,則輸出一個(gè)*號(hào)
               System.out.print("* ");
              else
               System.out.print("  ");
              if (weekday == Calendar.SATURDAY)         //到達(dá)周六,則換行
               System.out.println();
              d.add(Calendar.DAY_OF_YEAR,1);            //日期累加
             } while (d.get(Calendar.MONTH) == month);     //如果還是當(dāng)月,繼續(xù)循環(huán)
             System.out.println("\n");
            } while (d.get(Calendar.YEAR) == year);           //如果還是當(dāng)年,繼續(xù)循環(huán)
           }
          }
          posted on 2006-07-22 17:17 wqwqwqwqwq 閱讀(369) 評(píng)論(0)  編輯  收藏 所屬分類: Simple Java
          <2006年7月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345




          常用鏈接

          留言簿(10)

          隨筆分類(95)

          隨筆檔案(97)

          文章檔案(10)

          相冊(cè)

          J2ME技術(shù)網(wǎng)站

          java技術(shù)相關(guān)

          mess

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          校園夢(mèng)網(wǎng)網(wǎng)絡(luò)電話,中國(guó)最優(yōu)秀的網(wǎng)絡(luò)電話
          主站蜘蛛池模板: 兴海县| 营山县| 大新县| 顺平县| 杭锦后旗| 温泉县| 津市市| 巴里| 明溪县| 丽水市| 伊宁市| 临猗县| 德化县| 海安县| 竹溪县| 侯马市| 财经| 天门市| 连云港市| 乐平市| 抚宁县| 罗江县| 大姚县| 即墨市| 盘锦市| 彰化县| 定结县| 罗江县| 海城市| 双流县| 仙桃市| 浮山县| 龙岩市| 息烽县| 朝阳区| 新沂市| 钦州市| 措勤县| 渭源县| 武邑县| 蓬莱市|