javascript日期處理庫-Datejs.js

來源:互聯網
上載者:User

javascript日期處理庫-Datejs.js
 javascript日期處理庫-Datejs.js

  1. 當天時間

    Date.today();
  2. 比較兩個時間大小,返回-1,0,1

    var today = Date.today();var past = Date.today().add(-6).days();var future = Date.today().add(6).days();Date.compare(today, future);                    // -1Date.compare(today, new Date().clearTime());    // 0Date.compare(today, past)
  3. 比較時間是否在兩個時間內(閉區間)

    var past = new Date(2000, 4, 5);var future = new Date(2010, 11, 25)Date.today().between(past, future); // true|false
  4. 是否在指定日期後,是否在指定日期前

    var tomorrow = new Date().add(1).day(); Date.today().isAfter(tomorrow); // falseDate.today().isBefore(tomorrow); // truevar yesterday = new Date().add(-1).day();Date.today().isAfter(yesterday); // trueDate.today().isBefore(yesterday); // false// No date to compare to...     Date.today().isAfter(); // falseDate.today().isBefore(); // true
  5. 擷取一年中的第幾天

    Date.today().getOrdinalNumber()
  6. 擷取時區

    Date.today().getTimezone();
  7. 擷取指定時間的UTC位移量,'+'或者'-'

    Date.today().getUTCOffset(); // -0600
  8. 擷取指定時間的week of year(非UTC時間),這裡周一是一周的第一天,可不是周日哦

    Date.today().getWeek();
  9. 當前時區是否有夏令時

    Date.today().hasDaylightSavingTime();
  10. 判斷指定時間在當前時區中是否是在夏令時

    Date.today().isDaylightSavingTime(); // true|false
  11. 返回上/下一個day of week,如下,假如當天是周日

    Date.today().moveToDayOfWeek(0);     // move to next SundayDate.today().moveToDayOfWeek(0, -1); // move to last Sunday
  12. 返回當月的第一天的時間(假如當前日期是2007-10-19)

    Date.today().moveToFirstDayOfMonth(); // 1-Nov-2007
  13. 返回當月的最後一天的時間(假如當前日期是2007-10-19)

    new Date(2007, 10, 19).moveToLastDayOfMonth(); // 30-Nov-2007
  14. 返回指定時間的上一個或者下一個指定月份的時間,0代表一月,11代表十二月

    Date.today().moveToMonth(0);     // move to next JanuaryDate.today().moveToMonth(0, -1); // move to last January
  15. 設定時間

    Date.today().set({ day: 15, hour: 8 }); // Sets the day to the 15th day of the current month and the hour to 8 (AM).
  16. 設定時區

    Date.today().setTimezone(PST);
  17. 格式化日期(yyyy-MM-dd HH:mm:ss)

    Date.today().toString();           // native .toString() functionalityDate.today().toString(M/d/yyyy); // 11/19/2007Date.today().toString(d-MMM-yyyy); // 19-Nov-2007new Date().toString(HH:mm);      // 18:45

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.