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)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 简阳市| 灵台县| 鄂温| 玉山县| 湘潭县| 哈尔滨市| 克拉玛依市| 尉犁县| 星座| 海兴县| 潞城市| 富蕴县| 奎屯市| 南郑县| 迁西县| 邻水| 新泰市| 长岭县| 贺兰县| 南江县| 金乡县| 云霄县| 大荔县| 璧山县| 营口市| 万州区| 察哈| 苏州市| 彭州市| 新源县| 肥西县| 大竹县| 吉隆县| 慈溪市| 防城港市| 法库县| 霍州市| 赞皇县| 广灵县| 南开区| 会宁县|