java技術博客

          jsp博客
          數據加載中……
          FormateDateOutput.java
          /*
          *日歷按照格式輸出
          */
          import java.util.Calendar;
          import java.swing.JOptionPane;
          import java.text.SimpleDateFormat;
          public class FormatDateOutput{
          private int year;
          public static void main(String[] args){
          String input=JOptionPane.showInputDialog("請輸入有效的年分(YYYY):");
          int year1=Integer.parseInt(input);//將字符串轉化為整數
          FormateDateOutput out=new FormateDateOutput();
          out.setYear(year1);
          if(year1!=0&&input.length()==4)
          {
          out.FormateDateStr();
          }else{
          System.out.println("輸入的年份無效。");
          }System.exit(0);}
          public void FormateDateStr(){
          SimpleDateFormat formatter=(SimpleDateFormat)SimpleDateFormat.getDateInstance();
          formatter.applyPattern("yyyy-MM-dd");
          Calendar cal=Calendar.getInstance();
          for(int i=0;i<12;i++){
          cal.set(year,i,1);
          int temp=cal.getActualMaxmum(Calendar.DAY_OF_MONTH);
          for (int j=1;j<=temp;j++){
          cal.set(year,i,j);
          String str=formatter.format(cal.getTime());
          System.out.println("當前的時間是:"+str);}}}
          public void setYear(int year){
          this.year=year;
          System.out.println("the year is "+this.year);
          }
          public int getYear(){
          return year;}}

          posted on 2008-10-20 13:24 郭興華 閱讀(89) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 博罗县| 遂溪县| 白水县| 芦溪县| 寿光市| 镇江市| 罗山县| 华池县| 汽车| 拜泉县| 贺州市| 攀枝花市| 嘉峪关市| 黄骅市| 绥芬河市| 枣强县| 阳高县| 浮山县| 本溪| 旬邑县| 柳江县| 长丰县| 精河县| 随州市| 海兴县| 益阳市| 利川市| 且末县| 磐安县| 天水市| 漳平市| 苍梧县| 麦盖提县| 宜昌市| 日土县| 宜兰市| 黄浦区| 肥城市| 桑植县| 鄂州市| 高密市|