1. <tt id="5hhch"><source id="5hhch"></source></tt>
    1. <xmp id="5hhch"></xmp>

  2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

    <rp id="5hhch"></rp>
        <dfn id="5hhch"></dfn>

      1. Java認(rèn)證考試知識(shí)點(diǎn):Java時(shí)間類的函數(shù)

        時(shí)間:2020-09-21 12:41:25 JAVA認(rèn)證 我要投稿

        Java認(rèn)證考試知識(shí)點(diǎn):Java時(shí)間類的函數(shù)

          學(xué)習(xí)是一條慢長(zhǎng)而艱苦的道路,不能靠一時(shí)激情,也不是熬幾天幾夜就能學(xué)好的,必須養(yǎng)成平時(shí)努力學(xué)習(xí)的習(xí)慣,Java也不例外,下面小編為大家整理了Java里時(shí)間類以及函數(shù)的相關(guān)文章:

        Java認(rèn)證考試知識(shí)點(diǎn):Java時(shí)間類的函數(shù)

          1Calendar和Date的轉(zhuǎn)化

          (1)Calendar轉(zhuǎn)化為Date

          Calendar cal=Calendar.getInstance();

          Date date=cal.getTime();

          (2)Date轉(zhuǎn)化為Calendar

          Date date=new Date();

          Calendar cal=Calendar.getInstance();

          cal.setTime(date);

          2.計(jì)算某一月份的`最大天數(shù)

          Calendar time=Calendar.getInstance();

          time.clear();

          time.set(Calendar.YEAR,year);

          time.set(Calendar.MONTH,i-1);//注意,Calendar對(duì)象默認(rèn)一月為0

          int day=time.getActualMaximum(Calendar.DAY_OF_MONTH);//本月份的天數(shù)

          注:在使用set方法之前,必須先clear一下,否則很多信息會(huì)繼承自系統(tǒng)當(dāng)前時(shí)間

          3.格式化輸出日期時(shí)間

          Date date=new Date();

          SimpleDateFormat df=new SimpleDateFormat(“yyyy-MM-dd hh:mm:ss”);

          System.out.println(df.format(date));

          4.計(jì)算一年中的第幾星期

          (1)計(jì)算某一天是一年中的第幾星期

          Calendar cal=Calendar.getInstance();

          cal.set(Calendar.YEAR, 2006);

          cal.set(Calendar.MONTH,;

          cal.set(Calendar.DAY_OF_MONTH, 3);

          int weekno=cal.get(Calendar.WEEK_OF_YEAR);

          (2)計(jì)算一年中的第幾星期是幾號(hào)

          SimpleDateFormat df=new SimpleDateFormat(“yyyy-MM-dd”);

          Calendar cal=Calendar.getInstance();

          cal.set(Calendar.YEAR, 2006);

          cal.set(Calendar.WEEK_OF_YEAR, 1);

          cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

          System.out.println(df.format(cal.getTime()));

          輸出:

          2006-01-02

          5.add()和roll()的用法

          (1)add()方法

          SimpleDateFormat df=new SimpleDateFormat(“yyyy-MM-dd”);

          Calendar cal=Calendar.getInstance();

          cal.set(Calendar.YEAR, 2006);

          cal.set(Calendar.MONTH,;

          cal.set(Calendar.DAY_OF_MONTH, 3);

          cal.add(Calendar.DATE, -4);

          Date date=cal.getTime();

          System.out.println(df.format(date));

          cal.add(Calendar.DATE, 4);

          date=cal.getTime();

          System.out.println(df.format(date));

          輸出:

          2006-08-30

          2006-09-03

          (2)roll方法

          cal.set(Calendar.YEAR, 2006);

          cal.set(Calendar.MONTH,;

          cal.set(Calendar.DAY_OF_MONTH, 3);

          cal.roll(Calendar.DATE, -4);

          date=cal.getTime();

          System.out.println(df.format(date));

          cal.roll(Calendar.DATE, 4);

          date=cal.getTime();

          System.out.println(df.format(date));

          輸出:

          2006-09-29

          2006-09-03

          可見,roll()方法在本月內(nèi)循環(huán),一般使用add()方法;

        【Java認(rèn)證考試知識(shí)點(diǎn):Java時(shí)間類的函數(shù)】相關(guān)文章:

        Java時(shí)間類及函數(shù)用法10-12

        SUN認(rèn)證考試知識(shí)點(diǎn):java讀取文件內(nèi)容的函數(shù)09-27

        java認(rèn)證考試介紹10-03

        JAVA認(rèn)證考試細(xì)則10-03

        Sun java認(rèn)證考試答案11-12

        Sun Java認(rèn)證考試科目10-03

        sun java認(rèn)證考試介紹10-03

        JAVA考試認(rèn)證經(jīng)驗(yàn)分享11-05

        java認(rèn)證考試培訓(xùn)內(nèi)容11-01

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码

        1. <tt id="5hhch"><source id="5hhch"></source></tt>
          1. <xmp id="5hhch"></xmp>

        2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

          <rp id="5hhch"></rp>
              <dfn id="5hhch"></dfn>