<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## Java專題十:日期與時間 [TOC] ### 10.1.java.util.Date類 | 時間 | 說明 | | --- | --- | | year | y - 1900 | | month | [0 - 11] | | date (day of month) | [1 - 31] | | hour | [0 - 23] | | minute | [0 - 59] | | second | [0 - 61] | java.util.Date類中方法說明: | 方法 | 說明 | | --- | --- | |public Date() | 構造當前時間的Date | |public Date(long date) | 根據毫秒值構造Date | |public long getTime() | 獲取從January 1, 1970, 00:00:00 GMT起算的毫秒數 | |public int compareTo(Date anotherDate)| 比較2個Date的大小 | ### 10.2.java.util.Calendar類 | 方法 | 說明 | | --- | --- | |public static Calendar getInstance() | 構造當前時間的Calendar | |public int get(int field) | 獲取字段,見代碼2-1| |public void set(int field, int value)| 設置字段值| |public final Date getTime() | Calendar轉換成Date對象 | |public final void setTime(Date date)| Date轉換成Calendar對象 | |public long getTimeInMillis()| 獲取毫秒數 | |public void setTimeInMillis(long millis) | 設置毫秒數 | |public void add(int field, int amount) | 自動重新計算日期,見代碼2-2 | 代碼2-1: ``` Calendar cal = Calendar.getInstance(); cal.get(Calendar.YEAR); // year // JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, // AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER, UNDECIMBER cal.get(Calendar.MONTH) + 1; // month cal.get(Calendar.DATE); // day cal.get(Calendar.HOUR_OF_DAY); // hour cal.get(Calendar.MINUTE); // minute cal.get(Calendar.SECOND); // second cal.get(Calendar.MILLISECOND); // millisecond // AM = 0, PM = 1 cal.get(Calendar.AM_PM); // MONDAY = 2, TUESDAY = 3, WEDNESDAY = 4, THURSDAY = 5, // FRIDAY = 6, SATURDAY = 7, SUNDAY = 1 cal.get(Calendar.DAY_OF_WEEK); ``` 代碼2-2: ``` Calendar cal = Calendar.getInstance(); df.format(cal.getTime()); // 2020-03-20 cal.add(Calendar.DATE, 13); // 重新計算 df.format(cal.getTime()); // 2020-04-02 ``` ### 10.3.java.text.SimpleDateFormat類 #### 10.3.1.format方法:將Date和毫秒數轉換成String類型 - String format(Date date) - String format(milliseconds) ``` SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df.format(new Date()); df.format(System.currentTimeMillis()); df.format(Calendar.getInstance().getTime()); ``` #### 10.3.2.parse方法:將String類型轉換成Date類型 - Date parse(String source) throws ParseException ``` SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String formatTime = df.format(System.currentTimeMillis()); Date d = df.parse(formatTime); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看