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 郭興華 閱讀(90) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 罗定市| 西贡区| 读书| 桐庐县| 富阳市| 东安县| 莒南县| 隆德县| 桐柏县| 普兰店市| 双峰县| 宁晋县| 延吉市| 宣威市| 维西| 临西县| 泽普县| 宁强县| 嘉黎县| 宜宾县| 开封县| 北安市| 藁城市| 长阳| 洛扎县| 宿州市| 孟村| 南丹县| 嘉善县| 迭部县| 成安县| 庆元县| 勐海县| 白城市| 墨玉县| 呼伦贝尔市| 鹤庆县| 万山特区| 肇州县| 大新县| 临沂市|