列印Windows系統日曆格式

來源:互聯網
上載者:User

標籤:date類   calendar類   simpledateformat類   日曆   

*   列印Windows系統日曆格式 *  *     2016年4月16日  星期六  今年的107天 * *     日    一    二    三    四    五    六 *              1  2 *     3  4  5  6  7  8  9 *     10 11 12 13 14 15 16 *     17 18 19 20 21 22 23 *     24 25 26 27 28 29 30 * *   Date類  Calendar類  DateFormat類 SimpleDateFormat類的應用和練習 * */ import java.text.SimpleDateFormat;public class MyCalendar {public static void main(String[] args) {Date d=new Date();ShowMonth s=new ShowMonth();SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日  E  今年的第D天");System.out.println(sdf.format(d));System.out.println("日\t一\t二\t三\t四\t五\t六");s.show();}}
import java.util.Calendar;public class ShowMonth {   Calendar c=Calendar.getInstance();//獲得每個月的最大天數    int sumDays =c.getActualMaximum(Calendar.DATE);       public void show(){    //設定當前日期為第一天(1日)    c.set(Calendar.DAY_OF_MONTH, 1);      //得到當前(1日)是一周的第幾天    int a = c.get(Calendar.DAY_OF_WEEK);    //列印當前(1日)日期前面的空格      for(int i=1; i<a; i++) {              System.out.print("\t");          }            //列印每個月的日期      for(int i=1;i<=sumDays;i++){      System.out.print(i+"\t");      //如果是周六,換行輸出      if(c.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY){      System.out.println();      }    // 每次輸出日期後,將日期增加一天      c.add(Calendar.DAY_OF_MONTH, 1);      }        }    }


列印Windows系統日曆格式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.