Khoảng khăc. js đã được sử dụng thành công trong hàng triệu dự án và chúng tôi rất vui vì đã góp phần làm cho ngày và giờ tốt hơn trên web. Tính đến tháng 9 năm 2020, Moment nhận được hơn 12 triệu lượt tải xuống mỗi tuần. Tuy nhiên, Moment được xây dựng cho kỷ nguyên trước của hệ sinh thái JavaScript. Web hiện đại ngày nay trông khác nhiều. Moment đã phát triển phần nào trong những năm qua, nhưng về cơ bản nó vẫn giữ nguyên thiết kế như khi nó được tạo ra vào năm 2011. Dựa vào số lượng dự án phụ thuộc vào nó, chúng tôi chọn ưu tiên tính ổn định hơn các tính năng mới Ví dụ, xem xét rằng các đối tượng Khoảnh khắc có thể thay đổi. Đây là một nguồn khiếu nại phổ biến về Moment. Chúng tôi giải quyết vấn đề này nhưng nó vẫn gây ngạc nhiên cho hầu hết người dùng mới. Thay đổi Khoảnh khắc thành bất biến sẽ là một thay đổi đột phá đối với mọi dự án sử dụng nó. Tạo một "Moment v3" không thay đổi sẽ là một công việc to lớn và sẽ biến Moment thành một thư viện hoàn toàn khác. Vì điều này đã được thực hiện trong các thư viện khác, chúng tôi cảm thấy rằng điều quan trọng hơn là giữ lại API có thể thay đổi Một lập luận phổ biến khác chống lại việc sử dụng Moment trong các ứng dụng hiện đại là kích thước của nó. Khoảnh khắc không hoạt động tốt với các thuật toán "rung cây" hiện đại, do đó, nó có xu hướng tăng kích thước của gói ứng dụng web. Nếu một người cần hỗ trợ quốc tế hóa hoặc múi giờ, Moment có thể khá lớn. Các trình duyệt web hiện đại (và Node. js) hiển thị hỗ trợ quốc tế hóa và múi giờ thông qua đối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
68, được mã hóa thành ECMA-402. Các thư viện như Luxon (và các thư viện khác) tận dụng lợi thế này, giảm hoặc loại bỏ nhu cầu gửi các tệp dữ liệu của riêng bạnGần đây, Chrome Dev Tools đã bắt đầu hiển thị các đề xuất để thay thế Khoảnh khắc cho riêng kích thước. Chúng tôi thường ủng hộ động thái này Bạn cũng có thể muốn đọc - Có lẽ bạn không cần thời gian. js nữa
- Bạn không (có thể không) cần Khoảnh khắc. js
- Tại sao bạn không nên sử dụng Moment. js
- 4 lựa chọn thay thế cho thời điểm. js để quốc tế hóa ngày tháng
Nhóm Moment đã thảo luận về những vấn đề này rất lâu. Chúng tôi nhận thấy rằng nhiều dự án hiện tại có thể tiếp tục sử dụng Moment, nhưng chúng tôi không muốn Moment được sử dụng trong các dự án mới trong tương lai. Thay vào đó, chúng tôi muốn đó là sự lựa chọn tuyệt vời để sử dụng trong các ứng dụng hiện đại ngày nay. Chúng tôi cũng muốn thúc đẩy việc bổ sung ngôn ngữ JavaScript đang tìm kiếm phản hồi và cộng tác viên Hiện tại, chúng tôi thường coi Khoảnh khắc là một dự án kế thừa ở chế độ bảo trì. Nó không chết, nhưng nó thực sự được thực hiện Trong thực tế, điều này có nghĩa là - Chúng tôi sẽ không thêm các tính năng hoặc khả năng mới
- Chúng tôi sẽ không thay đổi API của Moment thành bất biến
- Chúng tôi sẽ không giải quyết các vấn đề về rung cây hoặc kích thước bó
- Chúng tôi sẽ không thực hiện bất kỳ thay đổi lớn nào (không có phiên bản 3)
- Chúng tôi có thể chọn không sửa lỗi hoặc hành vi kỳ quặc, đặc biệt nếu chúng là những vấn đề đã biết từ lâu
Liên quan cụ thể đến các tệp ngôn ngữ quốc tế hóa của Moment - Chúng tôi có thể chọn không chấp nhận các sửa đổi đối với chuỗi bản địa hóa hoặc định dạng ngày được bản địa hóa, đặc biệt nếu chúng đã được lập luận thành công cho biểu mẫu hiện tại của chúng
- Bạn phải đưa ra một lập luận thuyết phục mới cho những thay đổi ngôn ngữ với bằng chứng quan trọng, phi giai thoại để hỗ trợ cho quan điểm của bạn
- Nếu chuỗi hoặc định dạng bạn đang yêu cầu thay đổi được phản ánh trong CLDR, thì bạn phải gửi thay đổi ở đó trước và được chấp nhận
Tuy nhiên, vì chúng tôi hiểu rằng Khoảnh khắc đã được thiết lập tốt trong hàng triệu dự án hiện có - Chúng tôi sẽ giải quyết các vấn đề quan trọng về bảo mật khi chúng phát sinh
- Chúng tôi sẽ phát hành các bản cập nhật dữ liệu cho Múi giờ theo thời điểm sau khi phát hành cơ sở dữ liệu múi giờ IANA
Lý do để tiếp tục sử dụng MomentTrong hầu hết các trường hợp, bạn không nên chọn Moment cho các dự án mới. Tuy nhiên, có một số lý do có thể khiến bạn muốn tiếp tục sử dụng nó hỗ trợ trình duyệtKhoảnh khắc hoạt động tốt trên Internet Explorer 8 trở lên. Ngược lại, Luxon chỉ hoạt động trên IE 10 trở lên và yêu cầu một polyfill để làm như vậy. Các thư viện khác cũng gặp sự cố với Safari, đặc biệt là trên thiết bị di động. Nếu bạn có yêu cầu mạnh mẽ để hỗ trợ các trình duyệt cũ hơn, thì bạn có thể muốn gắn bó với Moment lâu hơn một chút Tuy nhiên, ngày. js báo cáo khả năng tương thích với IE8 trở lên, do đó bạn vẫn có thể muốn xem xét giải pháp thay thế đó Sự phụ thuộc của các thư viện khácMột số thư viện khác, đặc biệt là bộ chọn ngày và thư viện vẽ đồ thị, lấy Khoảnh khắc làm phụ thuộc. Nếu bạn đang sử dụng một thành phần như vậy và không thể tìm thấy một thành phần thay thế, thì bạn đã bao gồm Khoảnh khắc trong dự án của mình. Do đó, có thể hợp lý khi tiếp tục sử dụng Khoảnh khắc trong suốt dự án của bạn thay vì bao gồm một thư viện ngày và giờ khác quen thuộcNếu bạn là người dùng Moment lâu năm, bạn có thể đã hiểu rõ về API và các hạn chế của nó. Nếu đúng như vậy và các vấn đề nêu trên không phải là mối bận tâm của bạn, thì bạn chắc chắn có thể tiếp tục sử dụng nó chỉnh sửaCó một số tùy chọn tuyệt vời để xem xét sử dụng thay vì Khoảnh khắc Khi lựa chọn, hãy xem xét rằng - Một số thư viện được chia thành các mô-đun, plugin hoặc thư viện đồng hành
- Một số thư viện sử dụng API ECMAScript
// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
68 cho ngôn ngữ, múi giờ hoặc cả hai - Một số thư viện vẫn cung cấp các tệp miền địa phương và múi giờ của riêng họ như Moment và Moment-Timezone do
Dưới đây là các lựa chọn thay thế chúng tôi đề xuất LuxonLuxon có thể được coi là sự phát triển của Moment. Nó được tác giả bởi Isaac Cambron, một cộng tác viên lâu năm của Moment. Vui lòng đọc và các trang trong tài liệu Luxon - địa phương.
// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
68 được cung cấp - Múi giờ.
// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
68 được cung cấp
Ngày. jsNgày. js được thiết kế để thay thế tối giản cho Moment. js, sử dụng API tương tự. Đây không phải là sự thay thế tùy chọn, nhưng nếu bạn đã quen sử dụng API của Moment và muốn di chuyển nhanh chóng, hãy cân nhắc sử dụng Day. js - địa phương. Các tệp dữ liệu tùy chỉnh có thể được nhập riêng lẻ
- Múi giờ.
// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
68 được cung cấp, thông qua plugin
ngày-fnsDate-fns cung cấp một loạt hàm để thao tác với các đối tượng JavaScript // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74. Để biết thêm chi tiết, hãy cuộn đến "Tại sao lại là date-fns?" - địa phương. Các tệp dữ liệu tùy chỉnh có thể được nhập riêng lẻ
- Múi giờ.
// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
68 được cung cấp, thông qua một thư viện đồng hành riêng biệt
js-Jodajs-Joda là một cổng JavaScript của Three-Ten Backport của Java, là cơ sở để triển khai JSR-310 của gói Java SE 8 // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
76. Nếu bạn đã quen thuộc với // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
76, Joda-Time hoặc Noda Time, bạn sẽ thấy js-Joda có thể so sánh được- địa phương. Các tệp dữ liệu tùy chỉnh thông qua mô-đun bổ trợ
- Múi giờ. Các tệp dữ liệu tùy chỉnh thông qua mô-đun bổ trợ
Không có thư việnJavaScript luôn có một đối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74, đặc tả ECMAScript (ECMA-262) đã xác địnhKhi sử dụng các đối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74, hãy lưu ý những điều sauĐối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74 bên trong đại diện cho dấu thời gian Unix với độ chính xác đến mili giây. Nó cung cấp các chức năng sẽ chuyển đổi sang và từ múi giờ địa phương của hệ thống, nhưng bên trong nó luôn là UTC. Không giống như một đối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
81, nó không thể được đặt để sử dụng múi giờ khác; Sử dụng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
82 hoặc đã có vấn đề và được triển khai không nhất quán trong quá khứ. Định nghĩa phân tích cú pháp một biến thể của các chuỗi ISO 8601, trong đó các biểu mẫu chỉ có ngày (như // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
84) được phân tích cú pháp thành UTC, thay vì giờ địa phương như theo tiêu chuẩn ISO 8601. Ngay cả khi đó, không phải tất cả các triển khai hiện đại đều triển khai chính xác đặc điểm kỹ thuật này (e. g. , Cuộc đi săn). Các loại chuỗi khác có thể hoạt động, nhưng việc phân tích cú pháp chúng là triển khai cụ thể và có thể thay đổi đáng kể - đặc biệt là với các trình duyệt cũ hơn. Tùy thuộc vào cách triển khai và các thành phần được cung cấp trong chuỗi, bạn có thể ngạc nhiên với kết quả. Vì những lý do này, chúng tôi đồng ý với việc phân tích chuỗi với đối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74 không được khuyến khích
Các môi trường JavaScript hiện đại cũng sẽ triển khai đặc tả ECMA-402, cung cấp đối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
68 và xác định các tùy chọn hành vi của các hàm // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
88, ________0__89 và ________0____90 của đối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74Khi sử dụng đối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
68, hãy lưu ý những điều sau- Không phải mọi môi trường sẽ triển khai thông số kỹ thuật đầy đủ. Đặc biệt, nút. js yêu cầu hỗ trợ quốc tế hóa do ICU cung cấp. Xem nút. js để biết thêm chi tiết
- Bảng tương thích ECMAScript Intl (của kangax) có thể hữu ích trong việc xác định tính năng nào được hỗ trợ và tính năng nào không
- Hầu hết các môi trường mới hơn đều cung cấp hỗ trợ múi giờ IANA thông qua tùy chọn
// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
92 trong hàm tạo // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
93 (và trong // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
94, ________0____95 và // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
96). Tùy chọn này có thể được sử dụng để lấy dấu thời gian dựa trên UTC nội bộ của đối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74 và nhận chuỗi đã được chuyển đổi thành múi giờ được đặt tên. Tuy nhiên, nó không thể được sử dụng để chuyển đổi đối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74 sang múi giờ khác
Nếu các đối tượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74 và // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
68 đáp ứng nhu cầu của bạn và bạn hoàn toàn hiểu những hạn chế của chúng, thì bạn có thể cân nhắc sử dụng chúng trực tiếpchỉnh sửaTạm thời - Ngày và giờ tốt hơn bằng ngôn ngữ JavaScriptMột ngày không xa, chúng tôi hy vọng sẽ không còn nhu cầu lớn về thư viện ngày và giờ trong JavaScript nữa. Thay vào đó, chúng tôi sẽ có thể sử dụng các khả năng của chính ngôn ngữ JavaScript. Mặc dù ngày nay một số khả năng đã có ở đây với // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74 và // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
68, nhưng từ kinh nghiệm và dữ liệu, chúng tôi biết rằng vẫn còn chỗ đáng kể để cải thiệnNỗ lực tạo API ngày và giờ tốt hơn bằng ngôn ngữ JavaScript đang được thực hiện thông qua Đề xuất tạm thời ECMA TC39. Nó hiện đang ở Giai đoạn 3 của quy trình TC39 // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
69 sẽ là một đối tượng toàn cầu mới hoạt động như một không gian tên cấp cao nhất (như require.config({
config: {
moment: {
noGlobal: true
}
}
});
04). Nó hiển thị nhiều loại đối tượng riêng biệt bao gồm require.config({
config: {
moment: {
noGlobal: true
}
}
});
05, require.config({
config: {
moment: {
noGlobal: true
}
}
});
06, require.config({
config: {
moment: {
noGlobal: true
}
}
});
07, require.config({
config: {
moment: {
noGlobal: true
}
}
});
08, require.config({
config: {
moment: {
noGlobal: true
}
}
});
09, require.config({
config: {
moment: {
noGlobal: true
}
}
});
10 và một số đối tượng khác. Sách dạy nấu ăn tạm thời hiển thị nhiều "công thức nấu ăn" với các ví dụ về cách sử dụng các đồ vật này trong các tình huống khác nhauBạn có thể dùng thử Temporal ngay hôm nay, thông qua một polyfill phi sản xuất. Vui lòng dùng thử, nhưng đừng sử dụng nó trong sản xuất (chưa) Vui lòng cung cấp phản hồi và cân nhắc đóng góp cho nỗ lực này - đặc biệt nếu bạn có kinh nghiệm sử dụng Khoảnh khắc hoặc các thư viện ngày và giờ khác chỉnh sửaChúng tôi thực sự khuyên bạn nên đọc nếu bạn định sử dụng khoảnh khắc với Yêu cầu. js. Cũng nâng cấp lên 2. 14. 0 trở lên để có trải nghiệm tốt nhất Khi bắt đầu, bạn có thể có được khoảnh khắc thông qua bower hoặc node_modules hoặc bất kỳ thứ gì khác đặt khoảnh khắc. js cùng với thư mục ngôn ngữ trong thư mục cơ sở. Sau đó, bạn nên sử dụng một công cụ như Adapt-pkg-main hoặc thủ công -- sử dụng requirejs.config({
packages: [{
name: 'moment',
// This location is relative to baseUrl. Choose bower_components
// or node_modules, depending on how moment was installed.
location: '[bower_components|node_modules]/moment',
main: 'moment'
}]
});
Với cách thiết lập ở trên, bạn có thể yêu cầu lõi có ngôn ngữ require.config({
config: {
moment: {
noGlobal: true
}
}
});
11 và require.config({
config: {
moment: {
noGlobal: true
}
}
});
12 với ngôn ngữ require.config({
config: {
moment: {
noGlobal: true
}
}
});
13// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
Đối với các trường hợp sử dụng phức tạp hơn, vui lòng đọc Khoảnh khắc vẫn sẽ tạo ra một require.config({
config: {
moment: {
noGlobal: true
}
}
});
11 toàn cầu, hữu ích cho các plugin và mã của bên thứ ba khác. Nếu bạn muốn xóa toàn cầu đó, hãy sử dụng tùy chọn require.config({
config: {
moment: {
noGlobal: true
}
}
});
15 trên cấu hình mô-đunrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
Nếu bạn không chỉ định require.config({
config: {
moment: {
noGlobal: true
}
}
});
15 thì thời điểm được xuất trên toàn cầu sẽ in cảnh báo không dùng nữa. Từ bản phát hành chính tiếp theo, bạn sẽ phải tự xuất nó nếu muốn hành vi đóĐối với phiên bản 2. 5. x, trong trường hợp bạn sử dụng các plugin khác dựa trên Moment nhưng không tương thích với AMD, bạn có thể cần thêm vào r. cấu hình js Ghi chú. Để cho phép khoảnh khắc. js sẽ được tải trong môi trường requestjs, thời điểm được tạo dưới dạng mô-đun có tên. Do đó, thời điểm phải được tải chính xác như require.config({
config: {
moment: {
noGlobal: true
}
}
});
18, sử dụng require.config({
config: {
moment: {
noGlobal: true
}
}
});
19 để xác định thư mục. Thời điểm yêu cầu có đường dẫn như require.config({
config: {
moment: {
noGlobal: true
}
}
});
20 sẽ trả về require.config({
config: {
moment: {
noGlobal: true
}
}
});
21Ghi chú. Từ phiên bản 2. 9. 0 tự xuất dưới dạng mô-đun ẩn danh, vì vậy nếu bạn chỉ sử dụng lõi (không có ngôn ngữ / plugin), thì bạn không cần cấu hình nếu đặt nó ở vị trí không chuẩn 1. 0. 0+chỉnh sửamoment(String);
Khi tạo một khoảnh khắc từ một chuỗi, trước tiên chúng tôi kiểm tra xem chuỗi đó có khớp với các định dạng ISO 8601 đã biết hay không, sau đó chúng tôi kiểm tra xem chuỗi đó có khớp với định dạng hay không trước khi thả xuống phần sau của require.config({
config: {
moment: {
noGlobal: true
}
}
});
22 nếu không tìm thấy định dạng đã biếtvar day = moment("1995-12-25");
Cảnh báo. Hỗ trợ trình duyệt để phân tích chuỗi không nhất quán. Do không có thông số kỹ thuật về định dạng nào sẽ được hỗ trợ nên những gì hoạt động trong một số trình duyệt sẽ không hoạt động trong các trình duyệt khác Để có kết quả nhất quán khi phân tích cú pháp bất kỳ thứ gì khác ngoài chuỗi ISO 8601, bạn nên sử dụng Chuỗi ISO 8601 được hỗ trợMột chuỗi ISO 8601 yêu cầu một phần ngày 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
Phần thời gian cũng có thể được bao gồm, được phân tách với phần ngày bằng dấu cách hoặc chữ T viết hoa 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
Bất kỳ phần ngày nào cũng có thể có phần thời gian 2013-02-08 09 # A calendar date part and hour time part
2013-W06-5 09 # A week date part and hour time part
2013-039 09 # An ordinal date part and hour time part
Nếu bao gồm một phần thời gian, thì phần bù từ UTC cũng có thể được bao gồm như require.config({
config: {
moment: {
noGlobal: true
}
}
});
23, require.config({
config: {
moment: {
noGlobal: true
}
}
});
24, require.config({
config: {
moment: {
noGlobal: true
}
}
});
25 hoặc require.config({
config: {
moment: {
noGlobal: true
}
}
});
262013-02-08 09+07:00 # +-HH:mm
2013-02-08 09-0100 # +-HHmm
2013-02-08 09Z # Z
2013-02-08 09:30:26.123+07:00 # +-HH:mm
2013-02-08 09:30:26.123+07 # +-HH
Ghi chú. Hỗ trợ cho các định dạng tuần và thứ tự đã được thêm vào trong phiên bản 2. 3. 0 Nếu một chuỗi không khớp với bất kỳ định dạng nào ở trên và không thể phân tích cú pháp bằng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
82, thì require.config({
config: {
moment: {
noGlobal: true
}
}
});
28 sẽ trả về falsemoment("not a real date").isValid(); // false
Định dạng ngày giờ RFC 2822Trước khi phân tích cú pháp ngày giờ RFC 2822, chuỗi được xóa để xóa mọi nhận xét và/hoặc ký tự dòng mới. Các ký tự bổ sung có định dạng hợp pháp nhưng không bổ sung gì để tạo một phiên bản thời điểm hợp lệ Sau khi làm sạch, chuỗi được xác thực trong các phần được phân tách bằng dấu cách sau đây, tất cả đều sử dụng ngôn ngữ tiếng Anh // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
0- Ngày trong tuần bằng ba chữ cái, theo sau là dấu phẩy tùy chọn. (không bắt buộc)
- Ngày trong tháng (1 hoặc 2 chữ số), theo sau là tháng gồm ba chữ cái và năm gồm 2 hoặc 4 chữ số
- Hai chữ số giờ và phút cách nhau bởi dấu hai chấm (. ), theo sau tùy ý là dấu hai chấm khác và giây ở dạng 2 chữ số
- Múi giờ hoặc độ lệch ở một trong các định dạng sau
- UT. +0000
- giờ GMT. +0000
- EST. CST. MST. PST. EDT. CĐT. MDT. PDT. Múi giờ Hoa Kỳ*
- Một - tôi. K-Z. Múi giờ quân sự*
- Thời gian bù +/-9999
[*] Xem thông số kỹ thuật để biết chi tiết Trình phân tích cú pháp cũng xác nhận rằng ngày trong tuần (khi được đưa vào) nhất quán với ngày 1. 0. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
1Nếu bạn biết định dạng của chuỗi đầu vào, bạn có thể sử dụng định dạng đó để phân tích một khoảnh khắc // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
2Theo mặc định, trình phân tích cú pháp bỏ qua các ký tự không phải chữ và số, vì vậy cả hai ký tự sau đây sẽ trả về cùng một thứ // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
3Bạn có thể nhận được kết quả không mong muốn khi phân tích cả ngày và giờ. Ví dụ dưới đây có thể không phân tích cú pháp như bạn mong đợi // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
4Bạn có thể sử dụng chế độ nghiêm ngặt, chế độ này sẽ xác định lỗi phân tích cú pháp và đặt đối tượng Khoảnh khắc là không hợp lệ // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
5Mã thông báo phân tích cú pháp tương tự như mã thông báo định dạng được sử dụng trong require.config({
config: {
moment: {
noGlobal: true
}
}
});
29Mã thông báo năm, tháng và ngàyMã thông báo phân biệt chữ hoa chữ thường Đầu vàoVí dụMô tả_______34_______30____34_______314 hoặc năm có 2 chữ số. Ghi chú. Chỉ có 4 chữ số có thể được phân tích cú pháp trên chế độ require.config({
config: {
moment: {
noGlobal: true
}
}
});
32require.config({
config: {
moment: {
noGlobal: true
}
}
});
33require.config({
config: {
moment: {
noGlobal: true
}
}
});
342 chữ số nămrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
35require.config({
config: {
moment: {
noGlobal: true
}
}
});
36Năm với bất kỳ số lượng chữ số và ký hiệu nào_______34_______37require.config({
config: {
moment: {
noGlobal: true
}
}
});
38Quý của năm. Đặt tháng thành tháng đầu tiên trong quý. require.config({
config: {
moment: {
noGlobal: true
}
}
});
39require.config({
config: {
moment: {
noGlobal: true
}
}
});
40Month numberrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
41require.config({
config: {
moment: {
noGlobal: true
}
}
});
42Month name in locale set by require.config({
config: {
moment: {
noGlobal: true
}
}
});
43require.config({
config: {
moment: {
noGlobal: true
}
}
});
44require.config({
config: {
moment: {
noGlobal: true
}
}
});
45Day of monthrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
46require.config({
config: {
moment: {
noGlobal: true
}
}
});
47Day of month with ordinalrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
48require.config({
config: {
moment: {
noGlobal: true
}
}
});
49Day of yearrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
50require.config({
config: {
moment: {
noGlobal: true
}
}
});
51Unix timestamprequire.config({
config: {
moment: {
noGlobal: true
}
}
});
52require.config({
config: {
moment: {
noGlobal: true
}
}
});
53Unix ms timestamprequire.config({
config: {
moment: {
noGlobal: true
}
}
});
30 từ phiên bản 2. 10. 5 hỗ trợ năm có 2 chữ số ở chế độ không phải require.config({
config: {
moment: {
noGlobal: true
}
}
});
32 và chuyển đổi chúng thành năm gần 2000 (giống như require.config({
config: {
moment: {
noGlobal: true
}
}
});
33)require.config({
config: {
moment: {
noGlobal: true
}
}
});
35 đã được thêm vào 2. 11. 1. Nó sẽ khớp với bất kỳ số nào, đã ký hoặc chưa ký. Nó hữu ích cho những năm không có 4 chữ số hoặc trước kỷ nguyên chung. Nó có thể được sử dụng cho bất kỳ năm nàoMã thông báo tuần năm, tuần và ngày trong tuầnĐối với những điều này, mã thông báo chữ thường sử dụng ngày bắt đầu tuần nhận biết ngôn ngữ và mã thông báo chữ hoa sử dụng ngày bắt đầu ngày của tuần ISO Mã thông báo phân biệt chữ hoa chữ thường InputExampleDescriptionrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
58require.config({
config: {
moment: {
noGlobal: true
}
}
});
31Locale 4 digit week yearrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
60require.config({
config: {
moment: {
noGlobal: true
}
}
});
34Locale 2 digit week yearrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
62require.config({
config: {
moment: {
noGlobal: true
}
}
});
63Locale week of yearrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
64require.config({
config: {
moment: {
noGlobal: true
}
}
});
65Locale day of weekrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
66require.config({
config: {
moment: {
noGlobal: true
}
}
});
67Day name in locale set by require.config({
config: {
moment: {
noGlobal: true
}
}
});
43require.config({
config: {
moment: {
noGlobal: true
}
}
});
69require.config({
config: {
moment: {
noGlobal: true
}
}
});
31ISO 4 digit week yearrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
71require.config({
config: {
moment: {
noGlobal: true
}
}
});
34ISO 2 digit week yearrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
73require.config({
config: {
moment: {
noGlobal: true
}
}
});
63ISO week of yearrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
75require.config({
config: {
moment: {
noGlobal: true
}
}
});
76ISO day of weekCác định dạng nhận biết ngôn ngữCác định dạng ngày và giờ nhận biết ngôn ngữ cũng có sẵn bằng cách sử dụng require.config({
config: {
moment: {
noGlobal: true
}
}
});
77. Chúng đã được thêm vào trong phiên bản 2. 2. 1, ngoại trừ require.config({
config: {
moment: {
noGlobal: true
}
}
});
78 đã được thêm vào 2. 8. 4Mã thông báo phân biệt chữ hoa chữ thường InputExampleDescriptionrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
79require.config({
config: {
moment: {
noGlobal: true
}
}
});
80Date (in local format)require.config({
config: {
moment: {
noGlobal: true
}
}
});
81require.config({
config: {
moment: {
noGlobal: true
}
}
});
82Month name, day of month, yearrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
83require.config({
config: {
moment: {
noGlobal: true
}
}
});
84Month name, day of month, year, timerequire.config({
config: {
moment: {
noGlobal: true
}
}
});
85require.config({
config: {
moment: {
noGlobal: true
}
}
});
86Day of week, month name, day of month, year, timerequire.config({
config: {
moment: {
noGlobal: true
}
}
});
87require.config({
config: {
moment: {
noGlobal: true
}
}
});
88Time (without seconds)require.config({
config: {
moment: {
noGlobal: true
}
}
});
78require.config({
config: {
moment: {
noGlobal: true
}
}
});
90Time (with seconds)Mã thông báo giờ, phút, giây, mili giây và độ lệchMã thông báo phân biệt chữ hoa chữ thường Đầu vàoVí dụMô tả_______34_______91require.config({
config: {
moment: {
noGlobal: true
}
}
});
92Giờ (thời gian 24 giờ)require.config({
config: {
moment: {
noGlobal: true
}
}
});
93require.config({
config: {
moment: {
noGlobal: true
}
}
});
40Giờ (thời gian 12 giờ được sử dụng với require.config({
config: {
moment: {
noGlobal: true
}
}
});
95. )require.config({
config: {
moment: {
noGlobal: true
}
}
});
96require.config({
config: {
moment: {
noGlobal: true
}
}
});
97Hours (24 hour time from 1 to 24)require.config({
config: {
moment: {
noGlobal: true
}
}
});
95require.config({
config: {
moment: {
noGlobal: true
}
}
});
99Post or ante meridiem (Note the one character moment(String);
00 are also considered valid)moment(String);
01moment(String);
02Minutesmoment(String);
03moment(String);
02Secondsmoment(String);
05moment(String);
06Fractional secondsmoment(String);
07moment(String);
08Offset from UTC as require.config({
config: {
moment: {
noGlobal: true
}
}
});
23, require.config({
config: {
moment: {
noGlobal: true
}
}
});
24, or require.config({
config: {
moment: {
noGlobal: true
}
}
});
26Từ phiên bản 2. 10. 5. mã thông báo thứ hai phân số có độ dài từ 4 đến 9 có thể phân tích cú pháp bất kỳ số lượng chữ số nào, nhưng sẽ chỉ xem xét 3 chữ số hàng đầu (mili giây). Sử dụng nếu bạn có thời gian được in với nhiều chữ số phân số và muốn sử dụng đầu vào Lưu ý rằng số lượng moment(String);
12 ký tự được cung cấp chỉ liên quan khi phân tích cú pháp ở chế độ nghiêm ngặt. Ở chế độ tiêu chuẩn, moment(String);
12, moment(String);
14, moment(String);
15, moment(String);
16 đều tương đương và được hiểu là phân số của giây. Ví dụ: moment(String);
17 luôn là 120 mili giây, việc chuyển qua moment(String);
14 sẽ không khiến nó được hiểu là 12 mili giâymoment(String);
07 đã được thêm vào trong phiên bản 1. 2. 0moment(String);
20 đã được thêm vào trong phiên bản 1. 6. 0require.config({
config: {
moment: {
noGlobal: true
}
}
});
50 đã được thêm vào trong phiên bản 2. 0. 0moment(String);
22 đã được thêm vào trong phiên bản 2. 10. 5require.config({
config: {
moment: {
noGlobal: true
}
}
});
96 đã được thêm vào trong phiên bản 2. 13. 0Trừ khi bạn chỉ định chênh lệch múi giờ, việc phân tích cú pháp một chuỗi sẽ tạo ra một ngày theo múi giờ hiện tại // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
6Mã thông báo liên quan đến Năm kỷ nguyênMã thông báo phân biệt chữ hoa chữ thường Đầu vàoVí dụMô tả. yyyymoment(String);
24Yearsyomoment(String);
25Ordinal YearsNmoment(String);
26Abbr Era nameNNmoment(String);
26Abbr Era nameNNNmoment(String);
26Abbr Era nameNNNNmoment(String);
29Full Era nameNNNNNmoment(String);
26Narrow Era nameHỗ trợ kỷ nguyên đã được thêm vào trong 2. 25. 0. Mã thông báo/API vẫn đang thay đổi Ghi chú và gotchasNếu thời điểm kết quả từ đầu vào được phân tích cú pháp không tồn tại, thì require.config({
config: {
moment: {
noGlobal: true
}
}
});
28 sẽ trả về false// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
7Kể từ phiên bản 2. 0. 0, khóa ngôn ngữ có thể được chuyển làm tham số thứ ba cho moment(String);
32 và moment(String);
33// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
8Trình phân tích cú pháp của Moment rất dễ tha thứ và điều này có thể dẫn đến hành vi không mong muốn/không mong muốn Ví dụ, hành vi sau đây có thể được quan sát // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
9Trước 2. 13. 0 trình phân tích cú pháp thể hiện hành vi sau. Điều này đã được sửa chữa require.config({
config: {
moment: {
noGlobal: true
}
}
});
0Kể từ phiên bản 2. 3. 0, bạn có thể chỉ định một boolean cho đối số cuối cùng để khiến Moment sử dụng phân tích cú pháp nghiêm ngặt. Phân tích cú pháp nghiêm ngặt yêu cầu định dạng và đầu vào khớp chính xác, bao gồm cả dấu phân cách require.config({
config: {
moment: {
noGlobal: true
}
}
});
1Bạn có thể sử dụng cả ngôn ngữ và độ nghiêm ngặt require.config({
config: {
moment: {
noGlobal: true
}
}
});
2Phân tích cú pháp nghiêm ngặt thường là tùy chọn phân tích cú pháp tốt nhất. Để biết thêm thông tin về việc chọn phân tích cú pháp nghiêm ngặt và tha thứ, hãy xem phần Phân tích cú pháp hai chữ số nămTheo mặc định, năm có hai chữ số trên 68 được coi là vào những năm 1900 và những năm từ 68 trở xuống được coi là vào những năm 2000. Điều này có thể được thay đổi bằng cách thay thế phương thức moment(String);
34. Đối số duy nhất của phương thức này là một chuỗi chứa hai năm do người dùng nhập vào và sẽ trả về năm dưới dạng số nguyênrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
3Phân tích cú pháp giờ và phút được dánTừ phiên bản 2. 11. 0 phân tích cú pháp moment(String);
35, moment(String);
36, moment(String);
37 và moment(String);
38 được hỗ trợrequire.config({
config: {
moment: {
noGlobal: true
}
}
});
4 1. 0. 0+chỉnh sửarequire.config({
config: {
moment: {
noGlobal: true
}
}
});
5Nếu bạn không biết định dạng chính xác của chuỗi đầu vào, nhưng biết nó có thể là một trong nhiều chuỗi, bạn có thể sử dụng một mảng định dạng Điều này cũng giống như, chỉ khác là nó sẽ cố khớp đầu vào với nhiều định dạng require.config({
config: {
moment: {
noGlobal: true
}
}
});
6Bắt đầu từ phiên bản 2. 3. 0, Moment sử dụng một số phỏng đoán đơn giản để xác định định dạng nào sẽ sử dụng. theo thứ tự - Thích các định dạng dẫn đến ngày tháng hơn các định dạng không hợp lệ
- Thích các định dạng phân tích nhiều chuỗi hơn ít hơn và sử dụng nhiều định dạng hơn ít hơn, tôi. e. thích phân tích cú pháp chặt chẽ hơn
- Thích các định dạng sớm hơn trong mảng hơn sau này
require.config({
config: {
moment: {
noGlobal: true
}
}
});
7Bạn cũng có thể chỉ định một đối số miền địa phương và nghiêm ngặt. Chúng hoạt động giống như trường hợp định dạng duy nhất require.config({
config: {
moment: {
noGlobal: true
}
}
});
8Ghi chú. Phân tích cú pháp nhiều định dạng chậm hơn đáng kể so với phân tích cú pháp một định dạng. Nếu bạn có thể tránh nó, việc phân tích cú pháp một định dạng sẽ nhanh hơn nhiều 1. 0. 0+chỉnh sửarequire.config({
config: {
moment: {
noGlobal: true
}
}
});
9Bạn có thể tạo một khoảnh khắc với một dãy số phản ánh các tham số được truyền cho new Date() moment(String);
39moment(String);
0Bất kỳ giá trị nào trong năm qua là tùy chọn và sẽ mặc định là số thấp nhất có thể moment(String);
1Xây dựng với một mảng sẽ tạo ra một ngày trong múi giờ hiện tại. Để tạo một ngày từ một mảng tại UTC, hãy sử dụng moment(String);
40moment(String);
2Ghi chú. Bởi vì điều này phản ánh các tham số // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74 gốc, tháng, giờ, phút, giây và mili giây đều được lập chỉ mục bằng 0. Năm và ngày trong tháng được lập chỉ mục 1Đây thường là nguyên nhân gây ra sự thất vọng, đặc biệt là với các tháng, vì vậy hãy lưu ý Nếu ngày đại diện bởi mảng không tồn tại, require.config({
config: {
moment: {
noGlobal: true
}
}
});
28 sẽ trả về falsemoment(String);
3 1. 5. 0+chỉnh sửamoment(String);
4Theo mặc định, thời điểm phân tích cú pháp và hiển thị theo giờ địa phương Nếu bạn muốn phân tích cú pháp hoặc hiển thị một thời điểm theo giờ UTC, bạn có thể sử dụng moment(String);
33 thay vì moment(String);
32Điều này đưa chúng ta đến một tính năng thú vị của Moment. js. chế độ UTC Khi ở chế độ UTC, tất cả các phương thức hiển thị sẽ hiển thị theo giờ UTC thay vì giờ địa phương moment(String);
5Ngoài ra, khi ở chế độ UTC, tất cả các getter và setter sẽ sử dụng nội bộ các phương thức moment(String);
45 và moment(String);
46 thay vì các phương thức moment(String);
47 và moment(String);
48moment(String);
6Điều quan trọng cần lưu ý là mặc dù các màn hình khác nhau ở trên, nhưng cả hai đều có cùng thời điểm moment(String);
7Bất kỳ thời điểm nào được tạo bằng moment(String);
33 sẽ ở chế độ UTC và bất kỳ thời điểm nào được tạo bằng moment(String);
32 sẽ khôngĐể chuyển từ UTC sang giờ địa phương, bạn có thể sử dụng hoặc moment(String);
8 2. 3. 0+chỉnh sửamoment(String);
9Các chức năng phân tích chuỗi của Moment như moment(String);
51 và moment(String);
52 chấp nhận thông tin offset nếu được cung cấp, nhưng chuyển đổi đối tượng Moment kết quả thành thời gian cục bộ hoặc UTC. Ngược lại, moment(String);
53 phân tích cú pháp chuỗi nhưng giữ đối tượng Khoảnh khắc kết quả trong múi giờ có độ lệch cố định với độ lệch được cung cấp trong chuỗivar day = moment("1995-12-25");
0Nó cũng cho phép bạn chuyển các đối số miền địa phương và mức độ nghiêm ngặt var day = moment("1995-12-25");
1moment(String);
54 tương đương với việc phân tích cú pháp chuỗi và sử dụng moment(String);
55 để phân tích vùngvar day = moment("1995-12-25");
2 1. 7. 0+chỉnh sửavar day = moment("1995-12-25");
3Moment áp dụng các quy tắc khởi tạo chặt chẽ hơn hàm tạo // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
74var day = moment("1995-12-25");
4Bạn có thể kiểm tra xem Khoảnh khắc có coi ngày không hợp lệ hay không bằng cách sử dụng require.config({
config: {
moment: {
noGlobal: true
}
}
});
28. Bạn có thể kiểm tra các số liệu được sử dụng bởi moment(String);
58 bằng cách sử dụng moment(String);
59, trả về một đối tượngCác cờ phân tích cú pháp sau dẫn đến một ngày không hợp lệ moment(String);
60. Trường ngày bị tràn, chẳng hạn như tháng thứ 13, ngày thứ 32 của tháng (hoặc ngày 29 tháng 2 đối với các năm không nhuận), ngày thứ 367 của năm, v.v. moment(String);
60 chứa chỉ mục của đơn vị không hợp lệ để khớp với moment(String);
62 (xem bên dưới); moment(String);
64. Tên tháng không hợp lệ, chẳng hạn như moment(String);
65. Chứa chính chuỗi tháng không hợp lệ, nếu không thì nullmoment(String);
66. Một chuỗi đầu vào không chứa gì có thể phân tích cú pháp, chẳng hạn như moment(String);
67. Booleanmoment(String);
68. Một đầu vào moment(String);
69, như moment(String);
70. Booleanmoment(String);
71. Một danh sách định dạng trống, chẳng hạn như moment(String);
72. Booleanmoment(String);
73. Ngày được tạo rõ ràng là không hợp lệ, chẳng hạn như moment(String);
74. Boolean
Ngoài những điều trên, kể từ ngày 2. 13. 0, các cờ meridiem và parsedDateParts hoạt động cùng nhau để xác định tính hợp lệ của ngày moment(String);
75. Cho biết kinh tuyến (AM/PM) nào đã được phân tích cú pháp, nếu có. Chuỗimoment(String);
76. Trả về một mảng các phần ngày được phân tích cú pháp theo thứ tự giảm dần - i. e. parsedDateParts[0] === năm. Nếu không có bộ phận nào, nhưng kinh tuyến có giá trị, thì ngày không hợp lệ. Mảng
Ngoài ra, nếu Khoảnh khắc được phân tích cú pháp ở chế độ nghiêm ngặt, các cờ này phải trống để Khoảnh khắc hợp lệ moment(String);
77. mảng các chuỗi con định dạng không tìm thấy trong chuỗi đầu vàomoment(String);
78. mảng các chuỗi con đầu vào không khớp với chuỗi định dạng
Ghi chú. Khái niệm về giá trị của Moment trở nên chặt chẽ và nhất quán hơn giữa 2. 2 và 2. 3. Ghi chú. Hiệu lực được xác định khi tạo thời điểm. Một khoảnh khắc sửa đổi (tôi. e. moment(String);
79) sẽ vẫn có hiệu lựcNgoài ra, bạn có thể sử dụng moment(String);
80 để xác định đơn vị ngày nào bị trànvar day = moment("1995-12-25");
5Giá trị trả về có ý nghĩa như sau - năm
- tháng
- ngày
- giờ
- phút
- giây
- mili giây
Ghi chú. Trong trường hợp có nhiều đơn vị sai, đơn vị đầu tiên được trả lại (ví dụ: vì hiệu lực của ngày có thể phụ thuộc vào tháng) Khoảnh khắc không hợp lệNếu một khoảnh khắc không hợp lệ, nó sẽ hoạt động giống như một NaN trong các phép toán dấu phẩy động Tất cả những điều sau đây tạo ra những khoảnh khắc không hợp lệ moment(String);
81moment(String);
82moment(String);
83moment(String);
84moment(String);
85moment(String);
86moment(String);
87moment(String);
88moment(String);
89moment(String);
90moment(String);
91moment(String);
92
Sau đây tạo ra một phiên bản bản địa hóa của moment(String);
93moment(String);
94 kết quả là moment(String);
95 ở địa phương hiện tạimoment(String);
96moment(String);
97moment(String);
98moment(String);
99var day = moment("1995-12-25");
00var day = moment("1995-12-25");
01var day = moment("1995-12-25");
02 (Trước 2. 18. 0)var day = moment("1995-12-25");
03
Sự trở lại sau var day = moment("1995-12-25");
04var day = moment("1995-12-25");
05var day = moment("1995-12-25");
06var day = moment("1995-12-25");
07var day = moment("1995-12-25");
08var day = moment("1995-12-25");
09var day = moment("1995-12-25");
10var day = moment("1995-12-25");
11var day = moment("1995-12-25");
12var day = moment("1995-12-25");
13var day = moment("1995-12-25");
14var day = moment("1995-12-25");
15var day = moment("1995-12-25");
16var day = moment("1995-12-25");
17var day = moment("1995-12-25");
18var day = moment("1995-12-25");
19var day = moment("1995-12-25");
20var day = moment("1995-12-25");
21
Và những trả về moment(String);
69 hoặc var day = moment("1995-12-25");
23 với một số cấu trúcvar day = moment("1995-12-25");
24 trả về giá trị rỗng, giống như tất cả các getter có tên khácvar day = moment("1995-12-25");
25var day = moment("1995-12-25");
26 có tất cả các giá trị được đặt thành var day = moment("1995-12-25");
23var day = moment("1995-12-25");
28 trả về một đối tượng Ngày không hợp lệvar day = moment("1995-12-25");
29 trả về giá trị rỗngvar day = moment("1995-12-25");
30 trả về giá trị rỗngvar day = moment("1995-12-25");
31 trả về giá trị rỗngvar day = moment("1995-12-25");
02 trả về giá trị rỗng (Kể từ ngày 2. 18. 0)
1. 0. 0+chỉnh sửavar day = moment("1995-12-25");
6Thay đổi khoảnh khắc ban đầu bằng cách thêm thời gian Đây là một chức năng khá mạnh mẽ để thêm thời gian vào một thời điểm hiện tại. Để thêm thời gian, hãy nhập khóa thời gian bạn muốn thêm và số lượng bạn muốn thêm var day = moment("1995-12-25");
7Cũng có một số phím tốc ký nếu bạn thích toàn bộ thứ ngắn gọn đó var day = moment("1995-12-25");
8KeyShorthandyearsyquartersQmonthsMweekswdaysdhourshminutesmsecondssmillisecondsmsNếu bạn muốn thêm nhiều khóa khác nhau cùng một lúc, bạn có thể chuyển chúng vào dưới dạng đối tượng bằng chữ var day = moment("1995-12-25");
9There are no upper limits for the amounts, so you can overload any of the parameters 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
0Special considerations for months and yearsIf the day of the month on the original date is greater than the number of days in the final month, the day of the month will change to the last day in the final month 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
1There are also special considerations to keep in mind when adding time that crosses over daylight saving time. If you are adding years, months, weeks, or days, the original hour will always match the added hour Adding a month will add the specified number of months to the date 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
22013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
3If you are adding hours, minutes, seconds, or milliseconds, the assumption is that you want precision to the hour, and will result in a different hour 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
4Alternatively, you can use to add to moments 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
5Before version 2. 8. 0, the var day = moment("1995-12-25");
33 syntax was also supported. It has been deprecated in favor of var day = moment("1995-12-25");
342013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
6As of 2. 12. 0 when decimal values are passed for days and months, they are rounded to the nearest integer. Weeks, quarters, and years are converted to days or months, and then rounded to the nearest integer 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
7 1. 7. 0+chỉnh sửa2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
8Mutates the original moment by setting it to the start of a unit of time 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
9These shortcuts are essentially the same as the following 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
02013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
1As of version 2. 0. 0, var day = moment("1995-12-25");
35 replaced var day = moment("1995-12-25");
36Note. var day = moment("1995-12-25");
37 was added in version 2. 0. 0As of version 2. 1. 0, var day = moment("1995-12-25");
37 uses the locale aware week start dayNote. var day = moment("1995-12-25");
39 was added in version 2. 2. 0Note. var day = moment("1995-12-25");
40 was added as an alias for day in 2. 13. 0 2. 9. 0++chỉnh sửa2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
2Get or set the UTC offset in minutes Note. Unlike this function returns the real offset from UTC, not the reverse offset (as returned by var day = moment("1995-12-25");
42)Getting the var day = moment("1995-12-25");
43 of the current object2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
3Setting the UTC offset by supplying minutes. The offset is set on the moment object that var day = moment("1995-12-25");
44 is called on. If you are wanting to set the offset globally, try using moment-timezone. Note that once you set an offset, it's fixed and won't change on its own (i. e không có quy tắc DST). If you want an actual time zone -- time in a particular location, like var day = moment("1995-12-25");
45, consider moment-timezone2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
4If the input is less than var day = moment("1995-12-25");
46 and greater than var day = moment("1995-12-25");
47, it will interpret your input as hours instead2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
5It is also possible to set the UTC offset from a string 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
6moment(String);
55 will search the string for the last match of var day = moment("1995-12-25");
49, so you can even pass an ISO8601 formatted string with offset and the moment will be changed to that UTC offsetNote that if the string does not include 'Z', it must include the var day = moment("1995-12-25");
50 or var day = moment("1995-12-25");
51 character2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
7The var day = moment("1995-12-25");
43 function has an optional second parameter which accepts a boolean value indicating whether to keep the existing time of dayOne use of this feature is if you want to construct a moment with a specific time zone offset using only numeric input values 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
8 1. 0. 0+chỉnh sửa2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
9This is the most robust display option. It takes a string of tokens and replaces them with their corresponding values 2013-02-08 09 # A calendar date part and hour time part
2013-W06-5 09 # A week date part and hour time part
2013-039 09 # An ordinal date part and hour time part
0TokenOutputMonthM1 2 . 11 12Mo1st 2nd . 11th 12thMM01 02 . 11 12MMMJan Feb . Nov DecMMMMJanuary February . November DecemberQuarterQ1 2 3 4Qo1st 2nd 3rd 4thDay of MonthD1 2 . 30 31Do1st 2nd . 30th 31stDD01 02 . 30 31Day of YearDDD1 2 . 364 365DDDo1st 2nd . 364th 365thDDDD001 002 . 364 365Day of Weekd0 1 . 5 6do0th 1st . 5th 6thddSu Mo . Fr SadddSun Mon . Fri SatddddSunday Monday . Friday SaturdayDay of Week (Locale)e0 1 . 5 6Day of Week (ISO)E1 2 . 6 7Week of Yearw1 2 . 52 53wo1st 2nd . 52nd 53rdww01 02 . 52 53Week of Year (ISO)W1 2 . 52 53Wo1st 2nd . 52nd 53rdWW01 02 . 52 53YearYY70 71 . 29 30YYYY1970 1971 . 2029 2030YYYYYY-001970 -001971 . +001907 +001971 Note. (Bao trùm phạm vi giá trị toàn thời gian xấp xỉ 273.790 năm tiến hoặc lùi kể từ ngày 01 tháng 01 năm 1970)Y1970 1971. 9999 +10000 +10001 Ghi chú. Điều này tuân thủ tiêu chuẩn ISO 8601 cho các ngày sau năm 9999Era Yeary1 2. 2020. Thời đạiN, NN, NNNBC AD Ghi chú. Tên thời đại AbbrNNNN Before Christ, Anno Domini Ghi chú. Tên thời đại đầy đủNNNNNBC AD Ghi chú. Tên thời đại thu hẹpTuần Nămgg70 71. 29 30gggg1970 1971. 2029 2030Tuần Năm (ISO)GG70 71. 29 30GGGG1970 1971 . 2029 2030AM/PMAAM PMMaam pmHourH0 1. 22 23HH00 01 . 22 23h1 2 . 11 12hh01 02 . 11 12k1 2 . 23 24kk01 02 . 23 24Minutem0 1 . 58 59mm00 01 . 58 59Seconds0 1 . 58 59ss00 01 . 58 59Fractional SecondS0 1 . 8 9SS00 01 . 98 99SSS000 001 . 998 999SSSS . SSSSSSSSS000[0. ] 001[0. ] . 998[0. ] 999[0. ]Time Zonez or zzEST CST . MST PST Note. as of 1. 6. 0, the z/zz format tokens have been deprecated from plain moment objects. Read more about it here. However, they *do* work if you are using a specific time zone with the moment-timezone addon. Z-07. 00 -06. 00 . +06. 00 +07. 00ZZ-0700 -0600 . +0600 +0700Unix TimestampX1360013296Unix Millisecond Timestampx1360013296123require.config({
config: {
moment: {
noGlobal: true
}
}
});
50 was added in 2. 0. 0var day = moment("1995-12-25");
56 were added in 2. 1. 0require.config({
config: {
moment: {
noGlobal: true
}
}
});
52 was added in 2. 8. 4moment(String);
16 to var day = moment("1995-12-25");
59 were added in 2. 10. 5. They display 3 significant digits and the rest is filled with zerosvar day = moment("1995-12-25");
60 and var day = moment("1995-12-25");
61 were added in 2. 13. 0Localized formatsBecause preferred formatting differs based on locale, there are a few tokens that can be used to format a moment based on its locale There are upper and lower case variations on the same formats. The lowercase version is intended to be the shortened version of its uppercase counterpart TimeLT8. 30 PMTime with secondsLTS8. 30. 25 PMMonth numeral, day of month, yearL09/04/1986l9/4/1986Month name, day of month, yearLLSeptember 4, 1986llSep 4, 1986Month name, day of month, year, timeLLLSeptember 4, 1986 8. 30 PMlllSep 4, 1986 8. 30 PMMonth name, day of month, day of week, year, timeLLLLThursday, September 4, 1986 8. 30 PMllllThu, ngày 4 tháng 9 năm 1986 8. 30 PMvar day = moment("1995-12-25");
62 are available in 2. 0. 0. require.config({
config: {
moment: {
noGlobal: true
}
}
});
78 was added in 2. 8. 4Escaping charactersTo escape characters in format strings, you can wrap the characters in square brackets 2013-02-08 09 # A calendar date part and hour time part
2013-W06-5 09 # A week date part and hour time part
2013-039 09 # An ordinal date part and hour time part
1Similarities and differences with LDMLNote. While these date formats are very similar to LDML date formats, there are a few minor differences regarding day of month, day of year, and day of week For a breakdown of a few different date formatting tokens across different locales, see Formatting speedTo compare Moment. js formatting speed against other libraries, check out this comparison against other libraries Other tokensIf you are more comfortable working with strftime instead of LDML-like parsing tokens, you can use Ben Oakes' plugin. benjaminoakes/moment-strftime Default formatCalling require.config({
config: {
moment: {
noGlobal: true
}
}
});
29 without a format will default to var day = moment("1995-12-25");
65. Out of the box, var day = moment("1995-12-25");
65 is the ISO8601 format var day = moment("1995-12-25");
67As of version 2. 13. 0, when in UTC mode, the default format is governed by var day = moment("1995-12-25");
68 which is in the format var day = moment("1995-12-25");
69. This returns require.config({
config: {
moment: {
noGlobal: true
}
}
});
26 as the offset, instead of var day = moment("1995-12-25");
71In certain instances, a local timezone (such as var day = moment("1995-12-25");
72) may have a zero offset, and will be considered to be UTC. In such cases, it may be useful to set var day = moment("1995-12-25");
65 and var day = moment("1995-12-25");
68 to use the same formattingChanging the value of var day = moment("1995-12-25");
65 will only affect formatting, and will not affect parsing. for example2013-02-08 09 # A calendar date part and hour time part
2013-W06-5 09 # A week date part and hour time part
2013-039 09 # An ordinal date part and hour time part
2 1. 0. 0+chỉnh sửa2013-02-08 09 # A calendar date part and hour time part
2013-W06-5 09 # A week date part and hour time part
2013-039 09 # An ordinal date part and hour time part
3A common way of displaying time is handled by var day = moment("1995-12-25");
76. This is sometimes called timeago or relative time2013-02-08 09 # A calendar date part and hour time part
2013-W06-5 09 # A week date part and hour time part
2013-039 09 # An ordinal date part and hour time part
4If you pass var day = moment("1995-12-25");
54, you can get the value without the suffix2013-02-08 09 # A calendar date part and hour time part
2013-W06-5 09 # A week date part and hour time part
2013-039 09 # An ordinal date part and hour time part
5The base strings are . Time is rounded to the nearest second The breakdown of which string is displayed for each length of time is outlined in the table below RangeKeySample Output0 to 44 secondssa few seconds agounsetss44 seconds ago45 to 89 secondsma minute ago90 seconds to 44 minutesmm2 minutes ago . 44 minutes ago45 to 89 minuteshan hour ago90 minutes to 21 hourshh2 hours ago . 21 hours ago22 to 35 hoursda day ago36 hours to 25 daysdd2 days ago . 25 days ago26 to 45 daysMa month ago45 to 319 daysMM2 months ago . 10 months ago320 to 547 days (1. 5 years)ya year ago548 days+yy2 years ago . 20 years agoNote. From version 2. 10. 3, if the target moment object is invalid the result is the localized Invalid date string Note. The var day = moment("1995-12-25");
78 key was added in 2. 18. 0. It is an optional threshold. It will never display UNLESS the user manually sets the ss threshold. Until the var day = moment("1995-12-25");
78 threshold is set, it defaults to the value of the var day = moment("1995-12-25");
80 threshold minus 1 (so, invisible to the user) 2. 10. 3+chỉnh sửa2013-02-08 09 # A calendar date part and hour time part
2013-W06-5 09 # A week date part and hour time part
2013-039 09 # An ordinal date part and hour time part
6A common way of displaying time is handled by var day = moment("1995-12-25");
81. This is sometimes called timeago or relative timeThis is similar to , but gives the opposite interval. var day = moment("1995-12-25");
83This is similar to , but is special-cased for the current time. Use var day = moment("1995-12-25");
84, if you want to control the two end points of the interval2013-02-08 09 # A calendar date part and hour time part
2013-W06-5 09 # A week date part and hour time part
2013-039 09 # An ordinal date part and hour time part
7If you pass var day = moment("1995-12-25");
54, you can get the value without the prefix2013-02-08 09 # A calendar date part and hour time part
2013-W06-5 09 # A week date part and hour time part
2013-039 09 # An ordinal date part and hour time part
8Các chuỗi cơ sở là The breakdown of which string is displayed for each length of time is outlined in the table below RangeKeySample Output0 đến 44 giây trong giây45 đến 89 giâyphút một phút90 giây đến 44 phútmmin 2 phút. trong 44 phút45 đến 89 phút hin một giờ90 phút đến 21 giờ hin 2 giờ. trong 21 giờ22 đến 35 giờ trong một ngày36 giờ đến 25 ngàyddin 2 ngày. in 25 days26 to 45 daysMin a month45 to 319 daysMMin 2 months . trong 10 tháng320 đến 547 ngày (1. 5 năm) âm một năm548 ngày+yyin 2 năm. Trong 20 nămTừ phiên bản 2. 10. 3, nếu đối tượng thời điểm đích không hợp lệ, kết quả là chuỗi ngày không hợp lệ được bản địa hóa 1. 3. 0+chỉnh sửa2013-02-08 09 # A calendar date part and hour time part
2013-W06-5 09 # A week date part and hour time part
2013-039 09 # An ordinal date part and hour time part
9Thời gian theo lịch hiển thị thời gian liên quan đến một var day = moment("1995-12-25");
87 nhất định (mặc định là bắt đầu từ ngày hôm nay), nhưng hiển thị hơi khác so với thời gian của var day = moment("1995-12-25");
76var day = moment("1995-12-25");
89 sẽ định dạng một ngày với các chuỗi khác nhau tùy thuộc vào mức độ gần với ngày của var day = moment("1995-12-25");
87 (hôm nay theo mặc định) là ngàyTuần trước Thứ Hai tuần trước lúc 2. 30 Ngày hôm trước Hôm qua lúc 2. 30 Cùng ngày Hôm nay lúc 2. 30 AMNgày hôm sauNgày mai lúc 2. 30 AMTuần tớiChủ nhật lúc 2. 30 AMMọi thứ khác7/10/2011Các chuỗi này được bản địa hóa và từ 2. 10. 5 thời điểm hỗ trợ chỉ định định dạng đầu ra lịch cho mỗi lần gọi 2013-02-08 09+07:00 # +-HH:mm
2013-02-08 09-0100 # +-HHmm
2013-02-08 09Z # Z
2013-02-08 09:30:26.123+07:00 # +-HH:mm
2013-02-08 09:30:26.123+07 # +-HH
0var day = moment("1995-12-25");
91 được sử dụng làm định dạng khi thời điểm cách ngày var day = moment("1995-12-25");
87 hơn một tuầnGhi chú. Từ phiên bản 2. 14. 0, đối số định dạng cho lịch có thể là lệnh gọi lại được thực thi trong ngữ cảnh thời điểm với một đối số duy nhất ngay bây giờ 2013-02-08 09+07:00 # +-HH:mm
2013-02-08 09-0100 # +-HHmm
2013-02-08 09Z # Z
2013-02-08 09:30:26.123+07:00 # +-HH:mm
2013-02-08 09:30:26.123+07 # +-HH
1Note. From version 2. 25. 0 you can only pass a formats argument, it could be an object of strings and functions 2013-02-08 09+07:00 # +-HH:mm
2013-02-08 09-0100 # +-HHmm
2013-02-08 09Z # Z
2013-02-08 09:30:26.123+07:00 # +-HH:mm
2013-02-08 09:30:26.123+07 # +-HH
2 1. 0. 0+chỉnh sửa2013-02-08 09+07:00 # +-HH:mm
2013-02-08 09-0100 # +-HHmm
2013-02-08 09Z # Z
2013-02-08 09:30:26.123+07:00 # +-HH:mm
2013-02-08 09:30:26.123+07 # +-HH
3To get the difference in milliseconds, use var day = moment("1995-12-25");
93 like you would use var day = moment("1995-12-25");
942013-02-08 09+07:00 # +-HH:mm
2013-02-08 09-0100 # +-HHmm
2013-02-08 09Z # Z
2013-02-08 09:30:26.123+07:00 # +-HH:mm
2013-02-08 09:30:26.123+07 # +-HH
4To get the difference in another unit of measurement, pass that measurement as the second argument 2013-02-08 09+07:00 # +-HH:mm
2013-02-08 09-0100 # +-HHmm
2013-02-08 09Z # Z
2013-02-08 09:30:26.123+07:00 # +-HH:mm
2013-02-08 09:30:26.123+07 # +-HH
5To get the duration of a difference between two moments, you can pass var day = moment("1995-12-25");
95 as an argument into var day = moment("1995-12-25");
96. See the docs on for more infoThe supported measurements are var day = moment("1995-12-25");
97, var day = moment("1995-12-25");
98, var day = moment("1995-12-25");
99, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
00, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
01, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
02, and 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
03. For ease of development, the singular forms are supported as of 2. 0. 0. Units of measurement other than milliseconds are available in version 1. 1. 1Theo mặc định, var day = moment("1995-12-25");
93 sẽ cắt bớt kết quả đến 0 chữ số thập phân, trả về một số nguyên. If you want a floating point number, pass var day = moment("1995-12-25");
54 as the third argument. Before 2. 0. 0, var day = moment("1995-12-25");
93 returned a number rounded to the nearest integer, not a truncated number2013-02-08 09+07:00 # +-HH:mm
2013-02-08 09-0100 # +-HHmm
2013-02-08 09Z # Z
2013-02-08 09:30:26.123+07:00 # +-HH:mm
2013-02-08 09:30:26.123+07 # +-HH
6If the moment is earlier than the moment you are passing to 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
07, the return value will be negative2013-02-08 09+07:00 # +-HH:mm
2013-02-08 09-0100 # +-HHmm
2013-02-08 09Z # Z
2013-02-08 09:30:26.123+07:00 # +-HH:mm
2013-02-08 09:30:26.123+07 # +-HH
7An easy way to think of this is by replacing 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
08 with a minus operator2013-02-08 09+07:00 # +-HH:mm
2013-02-08 09-0100 # +-HHmm
2013-02-08 09Z # Z
2013-02-08 09:30:26.123+07:00 # +-HH:mm
2013-02-08 09:30:26.123+07 # +-HH
8Month and year diffsvar day = moment("1995-12-25");
93 has some special handling for month and year diffs. It is optimized to ensure that two months with the same date are always a whole number apartSo Jan 15 to Feb 15 should be exactly 1 month Feb 28 to Mar 28 should be exactly 1 month Feb 28 2011 to Feb 28 2012 should be exactly 1 year See more discussion on the month and year diffs here This change to month and year diffs was made in 2. 0. 0. As of version 2. 9. 0 diff also support quarter unit 2. 0. 0+chỉnh sửa2013-02-08 09+07:00 # +-HH:mm
2013-02-08 09-0100 # +-HHmm
2013-02-08 09Z # Z
2013-02-08 09:30:26.123+07:00 # +-HH:mm
2013-02-08 09:30:26.123+07 # +-HH
9Check if a moment is before another moment. The first argument will be parsed as a moment, if not already so moment("not a real date").isValid(); // false
0If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day moment("not a real date").isValid(); // false
1Like 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
10 and 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
11, any of the units of time that are supported for 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
12 are supported for 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
13moment("not a real date").isValid(); // false
2If nothing is passed to 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
13, it will default to the current timeNOTE. 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
15 has undefined behavior and should not be used. If the code runs fast the initial created moment would be the same as the one created in isBefore to perform the check, so the result would be var day = moment("1995-12-25");
04. But if the code runs slower it's possible that the moment created in isBefore is measurably after the one created in moment(String);
32, so the call would return var day = moment("1995-12-25");
54 2. 0. 0+chỉnh sửamoment("not a real date").isValid(); // false
3Check if a moment is the same as another moment. The first argument will be parsed as a moment, if not already so moment("not a real date").isValid(); // false
4If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter moment("not a real date").isValid(); // false
5When including a second parameter, it will match all units equal or larger. Passing in 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
19 will check 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
19 and 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
21. Passing in 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
22 will check 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
22, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
19, and 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
21moment("not a real date").isValid(); // false
6Like 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
10 and 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
13, any of the units of time that are supported for 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
12 are supported for 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
11moment("not a real date").isValid(); // false
2If the two moments have different timezones, the timezone of the first moment will be used for the comparison moment("not a real date").isValid(); // false
8NOTE. 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
30 has undefined behavior and should not be used. If the code runs fast the initial created moment would be the same as the one created in isSame to perform the check, so the result would be var day = moment("1995-12-25");
54. But if the code runs slower it's possible that the moment created in isSame is measurably after the one created in moment(String);
32, so the call would return var day = moment("1995-12-25");
04 2. 9. 0+chỉnh sửamoment("not a real date").isValid(); // false
9Check if a moment is between two other moments, optionally looking at unit scale (minutes, hours, days, etc). The match is exclusive. The first two arguments will be parsed as moments, if not already so // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
00Note that the order of the two arguments matter. ngày "nhỏ hơn" phải ở đối số đầu tiên // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
01Nếu bạn muốn giới hạn mức độ chi tiết ở một đơn vị khác với mili giây, hãy chuyển các đơn vị này làm tham số thứ ba // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
02Like 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
11, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
13, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
10 any of the units of time that are supported for 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
12 are supported for 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
38. Year, month, week, isoWeek, day, hour, minute, and secondVersion 2. 13. 0 introduces inclusivity. Một 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
39 biểu thị bao gồm một giá trị. A 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
40 biểu thị loại trừ. If the inclusivity parameter is used, both indicators must be passed// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
03Note that in the event that the 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
41 and 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
42 parameters are the same, but the inclusivity parameters are different, false will preside// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
04Nếu tham số bao gồm không được chỉ định, Moment sẽ mặc định là 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
43 1. 2. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
052013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
44 kiểm tra xem thời điểm hiện tại có phải là giờ mùa hè khôngGHI CHÚ. Chức năng này là một HACK. thời điểm không có cách nào để biết liệu một thời điểm nhất định có ở DST thực tế hay không. Một số thay đổi về thời gian trong một vùng có liên quan đến DST, một số thì không và không có thông tin múi giờ hoàn chỉnh thì không thể biết được Khoảnh khắc hiện đang kiểm tra thời gian mùa đông và mùa hè, và nếu phần bù khớp với phần bù mùa hè (và thời gian nghỉ hè khác với thời gian nghỉ mùa đông), thì nó sẽ báo cáo DST. Điều này hoạt động trong phần lớn các trường hợp, nhưng như đã đề cập ở trên, không "chính xác" và sẽ không hoạt động trong mọi trường hợp. Vì vậy, đừng đến với chúng tôi phàn nàn Múi giờ thời điểm sự kiện (tại thời điểm viết 0. 5. 37) không hỗ trợ thông tin DST (i. e có phải là đồng hồ chính thức trong DST tại một thời điểm nhất định hay không), vì vậy để mọi thứ trở nên tốt hơn, một số nội dung mới (và gói tzdata) phải diễn ra theo múi giờ // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
06 1. 0. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
07Theo mặc định, Khoảnh khắc. js đi kèm với chuỗi ngôn ngữ tiếng Anh (Hoa Kỳ). Nếu bạn cần các ngôn ngữ khác, bạn có thể tải chúng vào Khoảnh khắc. js để sử dụng sau Để tải một ngôn ngữ, hãy chuyển khóa và các giá trị chuỗi tới 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
45Bạn có thể tìm thêm chi tiết về từng phần của gói ngôn ngữ trong phần // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
08Thông tin chi tiết về 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
46 và 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
47 có thể được tìm thấy trong phầnSau khi bạn tải một ngôn ngữ, nó sẽ trở thành ngôn ngữ hoạt động. Để thay đổi ngôn ngữ đang hoạt động, chỉ cần gọi 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
45 bằng khóa của ngôn ngữ đã tải// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
09kể từ 2. 21. 0, Khoảnh khắc sẽ 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
49 nếu ngôn ngữ không khả dụngkể từ 2. 8. 0, việc thay đổi ngôn ngữ chung không ảnh hưởng đến các phiên bản hiện có // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
102013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
45 trả về ngôn ngữ được sử dụng. Điều này hữu ích vì Khoảnh khắc sẽ không thay đổi ngôn ngữ nếu nó không biết ngôn ngữ bạn chỉ định// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
11Bạn cũng có thể chỉ định một danh sách các ngôn ngữ và Moment sẽ sử dụng danh sách đầu tiên mà nó có bản địa hóa cho // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
12Moment cũng sẽ thử các chuỗi con của trình xác định ngôn ngữ từ cụ thể nhất đến ít cụ thể nhất cho đến khi tìm thấy một ngôn ngữ mà nó biết. Điều này hữu ích khi cung cấp Khoảnh khắc bằng chuỗi ngôn ngữ được lấy từ môi trường của người dùng, chẳng hạn như 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
51// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
13Cuối cùng, Moment sẽ tìm kiếm một cách thông minh thông qua một loạt các ngôn ngữ và chuỗi con của chúng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
14Logic hoạt động như sau -- ngôn ngữ tiếp theo được chọn và thử nguyên trạng. Nếu không thành công, mã thường cố gắng cắt bit cuối cùng (thường là ký hiệu quốc gia) và thử lại. Tuy nhiên, nếu phần tử mảng tiếp theo có tiền tố giống hoặc dài hơn phần tử được thử, thì quá trình lặp lại tiếp tục. Vì vậy, ví dụ nếu mảng có trình tự // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
15sau đó thử "AA-BB" đầu tiên, sau đó một giải pháp ngây thơ sẽ thử "AA", nhưng thay vào đó, giải pháp này sẽ kiểm tra xem "AA-CC" thực sự cụ thể hơn "AA", vì vậy, nó thử "AA-CC" . Vì vậy, cuối cùng, các ngôn ngữ sau được thử theo thứ tự này (giả sử tất cả đều không thành công nên ngôn ngữ tiếp theo sẽ được thử) // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
16 1. 7. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
17Cấu hình ngôn ngữ chung có thể gặp sự cố khi chuyển qua các khoảnh khắc có thể cần được định dạng thành ngôn ngữ khác // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
18Nếu bạn gọi 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
52 mà không có tham số, bạn sẽ lấy lại cấu hình ngôn ngữ sẽ được sử dụng cho thời điểm đó// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
19Nếu bạn cần truy cập dữ liệu ngôn ngữ trong giây lát, đây là cách ưu tiên để làm như vậy kể từ 2. 3. 0, bạn cũng có thể chỉ định một mảng các mã định danh ngôn ngữ. Nó hoạt động giống như cách nó làm trong 2. 3. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
20Đôi khi, rất hữu ích khi lấy danh sách các tháng hoặc ngày trong tuần ở một ngôn ngữ, chẳng hạn như khi điền vào menu thả xuống // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
21Trả về danh sách các tháng ở ngôn ngữ hiện tại // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
22Tương tự, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
53 trả về tên tháng viết tắt và 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
54, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
55, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
56 trả về danh sách các ngày trong tuầnBạn có thể chuyển một số nguyên vào từng hàm đó để biết tháng hoặc ngày trong tuần cụ thể // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
23kể từ 2. 13. 0, bạn có thể chuyển một bool làm tham số đầu tiên của các hàm ngày trong tuần. Nếu đúng, các ngày trong tuần sẽ được trả về theo thứ tự ngôn ngữ cụ thể. Chẳng hạn, trong tiếng Ả Rập, Thứ Bảy là ngày đầu tiên trong tuần, do đó // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
24Ghi chú. Không có tham số cụ thể của ngôn ngữ, các ngày trong tuần luôn có Chủ nhật là chỉ số 0, bất kể ngày đầu tuần của địa phương đó là gì Một số địa phương đưa ra những cân nhắc đặc biệt khi định dạng tên tháng. Ví dụ: định dạng tiếng Hà Lan viết tắt tháng không có dấu chấm, nhưng chỉ khi nó định dạng tháng giữa các dấu gạch ngang. Phương thức var day = moment("1995-12-25");
98 hỗ trợ chuyển định dạng để các tháng sẽ được liệt kê trong ngữ cảnh phù hợp// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
25Và cuối cùng, bạn có thể kết hợp cả tùy chọn định dạng và tùy chọn số nguyên // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
26 2. 8. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
27Bạn có thể truy cập các thuộc tính của ngôn ngữ hiện được tải thông qua hàm 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
58. Nó trả về ngôn ngữ hiện tại hoặc một ngôn ngữ với khóa đã cho// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
28Đối tượng được trả về có các phương thức sau // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
29Thông tin chi tiết về 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
59 có thể được tìm thấy trong phầnKhoảng khăc. js rất dễ tùy chỉnh. Nói chung, bạn nên tạo cài đặt ngôn ngữ với các tùy chỉnh của mình // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
30Bạn có thể xóa một ngôn ngữ đã xác định trước đó bằng cách chuyển moment(String);
69 làm đối số thứ hai. Ngôn ngữ đã xóa sẽ không còn khả dụng để sử dụng// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
31kể từ 2. 12. 0, có thể tạo ngôn ngữ kế thừa từ ngôn ngữ gốc // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
32Các thuộc tính không được chỉ định trong ngôn ngữ sẽ được kế thừa từ ngôn ngữ gốc kể từ 2. 16. 0, có thể xác định ngôn ngữ có cha mẹ chưa được xác định hoặc tải // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
33kể từ 2. 21. 0 khi cố gắng tạo một khoảnh khắc với ngôn ngữ mới được xác định, khoảnh khắc sẽ cố tải cha mẹ xuống nếu nó tồn tại. Không thành công, nó sẽ mặc định cha mẹ thành ngôn ngữ toàn cầu As of 2. 12. 0 cũng có thể cập nhật các thuộc tính của ngôn ngữ // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
34Bất kỳ thuộc tính nào được chỉ định sẽ được cập nhật, trong khi các thuộc tính khác sẽ giữ nguyên. Chức năng này không ảnh hưởng đến những khoảnh khắc đã tồn tại. Lưu ý rằng việc gọi 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
61 cũng thay đổi ngôn ngữ toàn cầu hiện tại thành ngôn ngữ được cập nhật; Để hoàn nguyên một bản cập nhật, hãy sử dụng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
352. 12. 0 không dùng nữa bằng cách sử dụng require.config({
config: {
moment: {
noGlobal: true
}
}
});
43 để thay đổi ngôn ngữ hiện có. Sử dụng 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
63 để thay thế 1. 0. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
362013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
64 phải là một mảng tên tháng// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
37Nếu bạn cần xử lý nhiều hơn để tính tên của tháng, (ví dụ: nếu có ngữ pháp khác nhau cho các định dạng khác nhau), thì 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
64 có thể là một hàm có chữ ký sau. Nó phải luôn trả về một tên tháng// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
38Từ phiên bản 2. 11. 0 tháng cũng có thể là một đối tượng, chỉ định các hình thức 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
66 và 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
67 (chỉ định và buộc tội). Biểu thức chính quy được chạy trên định dạng để kiểm tra xem có sử dụng biểu mẫu 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
67 hay không là 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
69. Từ phiên bản 2. 14. 0 một số khác có thể được chỉ định bằng phím 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
70// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
39 1. 0. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
402013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
71 phải là một mảng tên các ngày trong tuần// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
412013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
71 cũng có thể là chức năng gọi lại// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
42Ghi chú. Từ phiên bản 2. 11. 0 định dạng/trường hợp độc lập cũng có thể được thông qua. 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
70 sẽ được sử dụng đối với chuỗi định dạng đầy đủ để xác định nên sử dụng biểu mẫu nào// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
43 1. 0. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
442013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
74 phải là một đối tượng của chuỗi thay thế cho var day = moment("1995-12-25");
94// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
452013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
76 đề cập đến tiền tố/hậu tố cho những ngày trong tương lai và 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
77 đề cập đến tiền tố/hậu tố cho những ngày trong quá khứ. Đối với tất cả những người khác, một ký tự đơn đề cập đến số ít và một ký tự kép đề cập đến số nhiềuNếu một ngôn ngữ yêu cầu xử lý bổ sung cho mã thông báo, thì nó có thể đặt mã thông báo làm hàm có chữ ký sau. Hàm sẽ trả về một chuỗi // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
46Đối số 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
78 đề cập đến khóa thay thế trong đối tượng 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
74. (ví dụ. 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
80, v.v. )Đối số 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
81 đề cập đến số lượng đơn vị cho khóa đó. Đối với 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
82, số này là số phút, v.v.Đối số 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
83 sẽ đúng nếu mã thông báo sẽ được hiển thị mà không có hậu tố và sai nếu nó sẽ được hiển thị với hậu tố. (Lý do logic đảo ngược là vì hành vi mặc định là hiển thị với hậu tố. )Đối số 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
84 sẽ đúng nếu nó sẽ sử dụng hậu tố/tiền tố tương lai và sai nếu nó sẽ sử dụng tiền tố/hậu tố quá khứGhi chú. Xử lý cho 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
85 và 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
86 đã được thêm vào 2. 25. 0 2. 7. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
472013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
87 có các ngưỡng xác định thời điểm một đơn vị được coi là phút, giờ, v.v. Ví dụ: theo mặc định, hơn 45 giây được coi là một phút, hơn 22 giờ được coi là một ngày, v.v. Để thay đổi các giới hạn đó, hãy sử dụng 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
88 trong đó đơn vị là một trong số var day = moment("1995-12-25");
78, var day = moment("1995-12-25");
80, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
82, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
92, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
93, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
85, 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
95đơn vị nghĩa là số lần sử dụng là vài giây số giây nhỏ nhất được tính bằng giây, trừ 1. Phải được đặt sau khi đặt đơn vị `s` hoặc không đặt đơn vị `s`. ssecondsố giây ít nhất được coi là một phút. mminutes số phút ít nhất được coi là một giờ. hhourssố giờ ít nhất được coi là một ngày. ddaysít nhất số ngày được coi là một tuần. wweeksố tuần ít nhất được coi là một tháng. Không được sử dụng theo mặc định. Mtháng số tháng ít nhất được coi là một năm. // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
48Ghi chú. Đơn vị tuần đã được thêm vào trong 2. 25. 0. Theo mặc định, nó không được sử dụng (đặt thành null), nhưng bạn có thể đặt thành giá trị khác null và cũng (tùy chọn) đặt 2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
93 thấp hơn, để nó chuyển từ vài ngày sang vài tuần trước đóGhi chú. Truy xuất ngưỡng đã được thêm vào trong 2. 8. 1 Ghi chú. Truy xuất và đặt ngưỡng var day = moment("1995-12-25");
78 đã được thêm vào 2. 18. 0 1. 0. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
492013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
98 phải là một số nguyên đại diện cho ngày đầu tuần, 0 là Chủ Nhật, 1 là Thứ Hai,. , 6 là thứ bảy2013-02-08 # A calendar date part
2013-02 # A month date part
2013-W06-5 # A week date part
2013-039 # An ordinal date part
20130208 # Basic (short) full date
201303 # Basic (short) year+month
2013 # Basic (short) year only
2013W065 # Basic (short) week, weekday
2013W06 # Basic (short) week only
2013050 # Basic (short) ordinal date (year + day-of-year)
99 phải là số nguyên. 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
00 được sử dụng cùng với 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
01 để xác định tuần đầu tiên của năm. 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
00 được tính là 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
03, trong đó 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
04 là ngày đầu tiên của tháng 1 phải thuộc tuần đầu tiên của năm// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
50 2. 25. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
51Chỉ định thời đại cho một ngôn ngữ cụ thể. Một thời đại là một khoảng thời gian với tên và đánh số năm. Số năm tuyệt đối (như 2020) cũng có thể được chỉ định là 2020 AD. năm thứ 2020 của kỷ nguyên sau công nguyên. Tương tự, số năm tuyệt đối -0500 có thể được mô tả là 501 trước Công nguyên, năm thứ 501 kể từ thời đại trước Công nguyên // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
522013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
05 và 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
06 chi phối hướng đi của thời đại. Như trong trường hợp của 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
07, nó phát triển về phía 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
08, do đó 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
05 > 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
06. Đối với các thời đại tăng dần về phía +Vô cực 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
05 < 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
06Phân tích cú pháp/định dạng thời đại được thực hiện bằng mã thông báo 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
13, 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
14 và 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
15Ghi chú. Các API liên quan đến thời đại có thể thay đổi 1. 6. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
53Để tạo khoảng thời gian, hãy gọi 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
16 với khoảng thời gian tính bằng mili giây// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
54Nếu bạn muốn tạo khoảnh khắc với đơn vị đo khác mili giây, bạn có thể truyền đơn vị đo cũng được // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
55Cách viết tắt tương tự cho 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
17 và 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
18 cũng hoạt động ở đâyKeyShorthandyearsymonthsMweekswdaysdhourshminutesmsecondssmillisecondsmsGiống như 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
17, bạn có thể truyền một đối tượng giá trị nếu bạn cần nhiều đơn vị đo lường khác nhau// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
56kể từ 2. 1. 0, thời điểm hỗ trợ phân tích cú pháp ASP. NET phong cách khoảng thời gian. Các định dạng sau được hỗ trợ Định dạng là một chuỗi giờ, phút, giây được phân tách bằng dấu hai chấm như 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
20. Số ngày có thể được bắt đầu bằng dấu phân cách dấu chấm như vậy 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
21. Một phần giây cũng được hỗ trợ 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
22// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
57kể từ 2. 3. 0, thời điểm cũng hỗ trợ phân tích thời lượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
58kể từ 2. 11. 0, chuỗi định dạng thời lượng có khoảng cách giữa ngày và phần còn lại được hỗ trợ // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
59kể từ 2. 13. 0, các dấu hiệu âm và dương hỗn hợp được hỗ trợ khi phân tích thời lượng // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
60kể từ 2. 18. 0, thời lượng không hợp lệ được hỗ trợ, tương tự như thời điểm không hợp lệ. Để tạo khoảng thời gian không hợp lệ, bạn có thể chuyển var day = moment("1995-12-25");
23 cho giá trị của một đơn vịTrong các bản phát hành sắp tới, thời lượng không hợp lệ sẽ bao gồm nhiều trường hợp hơn (như giá trị null cho đơn vị) // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
61 1. 6. 0+chỉnh sửa// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
62Đôi khi, bạn muốn tất cả những điều tốt đẹp của var day = moment("1995-12-25");
94 nhưng bạn không muốn phải tạo hai khoảnh khắc, bạn chỉ muốn hiển thị một khoảng thời gianNhập 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
25// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
63Theo mặc định, chuỗi trả về mô tả khoảng thời gian 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
26 (không có hậu tố). Nếu bạn muốn thời lượng định hướng 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
27, 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
28 (có hậu tố), hãy chuyển true như bên dưới// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
64Đối với các hậu tố trước đây, hãy chuyển vào một số âm // only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
65Thời lượng không hợp lệ được nhân hóa thành phiên bản địa phương hóa của 2013-02-08T09 # An hour time part separated by a T
2013-02-08 09 # An hour time part separated by a space
2013-02-08 09:30 # An hour and minute time part
2013-02-08 09:30:26 # An hour, minute, and second time part
2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
20130208T080910,123 # Short date and time up to ms, separated by comma
20130208T080910.123 # Short date and time up to ms
20130208T080910 # Short date and time up to seconds
20130208T0809 # Short date and time up to minutes
20130208T08 # Short date and time, hours only
29// only needing core
define(['moment'], function (moment) {
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
});
// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
moment.locale('de');
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});
// async load locale
define(['require', 'moment'], function(require, moment) {
// Inside some module after the locale is detected. This is the
// case where the locale is not known before module load time.
require(['moment/locale/de'], function(localeModule) {
// here the locale is loaded, but not yet in use
console.log(moment().format('LLLL')); // 'Friday, June 24, 2016 1:42 AM'
moment.locale('de');
// Use moment now that the locale has been properly set.
console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
})
});
66Đầu ra nhân hóa có thể được cấu hình với các ngưỡng thời gian tương đối. Để chỉ định các ngưỡng cho một lời gọi nhân hóa cụ thể, hãy chuyển chúng dưới dạng đối số duy nhất hoặc sau hậu tố arg |