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ạnRecently, Chrome Dev Tools started showing recommendations for replacing Moment for the size alone. We generally support this move
You may also want to read
- You Probably Don't Need Moment. js Anymore
- You don't [may not] need Moment. js
- Why you shouldn't use Moment. js
- 4 alternatives to moment. js for internationalizing dates
The Moment team has discussed these issues at length. We recognize that many existing projects may continue to use Moment, but we would like to discourage Moment from being used in new projects going forward. Instead, we would like to that are excellent choices for use in modern applications today. We would also like to promote the addition to the JavaScript language, which is looking for feedback and contributors
We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done
In practice, this means
- We will not be adding new features or capabilities
- We will not be changing Moment's API to be immutable
- We will not be addressing tree shaking or bundle size issues
- We will not be making any major changes [no version 3]
- We may choose to not fix bugs or behavioral quirks, especially if they are long-standing known issues
With specific regard to Moment's internationalization locale files
- We may choose to not accept corrections to locale strings or localized date formats, especially if they have been argued successfully for their present form
- 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 Moment
Trong 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ệt
Khoả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ác
Mộ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ộc
Nế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
68 cho ngôn ngữ, múi giờ hoặc cả hai// 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' }] }];
- 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
Luxon
Luxon 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.
68 được cung cấ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' }] }];
- Múi giờ.
68 được cung cấ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' }] }];
Ngày. js
Ngà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ờ.
68 được cung cấp, thông qua plugin// 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' }] }];
ngày-fns
Date-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ờ.
68 được cung cấp, thông qua một thư viện đồng hành riêng biệ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' }] }];
js-Joda
js-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ện
JavaScript 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
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;// 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' }] }];
Sử dụng
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// 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' }] }];
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
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,// 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' }] }];
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// 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' }] }];
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ữ JavaScript
Mộ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ù một số khả năng hiện 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 or above for best experience
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ột 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ó ở một 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 2822
Trướ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
[*] See of the specification for details
The parser also confirms that the day-of-week [when included] is consistent with the date
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'
}]
}];
1If you know the format of an input string, you can use that to parse a moment
// 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'
}]
}];
2The parser ignores non-alphanumeric characters by default, so both of the following will return the same thing
// 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'
}]
}];
3You may get unexpected results when parsing both date and time. The below example may not parse as you expect
// 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'
}]
}];
4You can use strict mode, which will identify the parsing error and set the Moment object as invalid
// 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'
}]
}];
5The parsing tokens are similar to the formatting tokens used in
require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
29Year, month, and day tokens
Tokens are case-sensitive
InputExampleDescriptionrequire.config[{
config: {
moment: {
noGlobal: true
}
}
}];
30require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
314 or 2 digit year. Note. Only 4 digit can be parsed on require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
32 moderequire.config[{
config: {
moment: {
noGlobal: true
}
}
}];
33require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
342 digit yearrequire.config[{
config: {
moment: {
noGlobal: true
}
}
}];
35require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
36Year with any number of digits and signrequire.config[{
config: {
moment: {
noGlobal: true
}
}
}];
37require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
38Quarter of year. Sets month to first month in quarter. 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 from version 2. 10. 5 supports 2 digit years in non require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
32 mode, and converts them to a year near 2000 [same as require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
33]require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
35 was added in 2. 11. 1. It will match any number, signed or unsigned. It is useful for years that are not 4 digits or are before the common era. It can be used for any yearWeek year, week, and weekday tokens
For these, the lowercase tokens use the locale aware week start days, and the uppercase tokens use the ISO week date start days
Tokens are case-sensitive
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 weekLocale aware formats
Locale aware date and time formats are also available using
require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
77. They were added in version 2. 2. 1, except require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
78 which was added 2. 8. 4Tokens are case-sensitive
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]Hour, minute, second, millisecond, and offset tokens
Tokens are case-sensitive
InputExampleDescriptionrequire.config[{
config: {
moment: {
noGlobal: true
}
}
}];
91require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
92Hours [24 hour time]require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
93require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
40Hours [12 hour time used with 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
}
}
}];
26From version 2. 10. 5. fractional second tokens length 4 up to 9 can parse any number of digits, but will only consider the top 3 [milliseconds]. Use if you have the time printed with many fractional digits and want to consume the input
Note that the number of
moment[String];
12 characters provided is only relevant when parsing in strict mode. In standard mode, moment[String];
12, moment[String];
14, moment[String];
15, moment[String];
16 are all equivalent, and interpreted as fractions of a second. For example, moment[String];
17 is always 120 milliseconds, passing moment[String];
14 will not cause it to be interpreted as 12 millisecondsmoment[String];
07 were added in version 1. 2. 0moment[String];
20 were added in version 1. 6. 0require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
50 was added in version 2. 0. 0moment[String];
22 were added in version 2. 10. 5require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
96 were added in version 2. 13. 0Unless you specify a time zone offset, parsing a string will create a date in the current time zone
// 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'
}]
}];
6Era Year related tokens
Tokens are case-sensitive
InputExamplesDescriptiony . 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 nameEra support was added in 2. 25. 0. The tokens/API are still in flux
Notes and gotchas
If the moment that results from the parsed input does not exist,
require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
28 will return 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'
}]
}];
7As of version 2. 0. 0, a locale key can be passed as the third parameter to
moment[String];
32 and 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'
}]
}];
8Moment's parser is very forgiving, and this can lead to undesired/unexpected behavior
For example, the following behavior can be observed
// 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'
}]
}];
9Previous to 2. 13. 0 the parser exhibited the following behavior. This has been corrected
require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
0As of version 2. 3. 0, you may specify a boolean for the last argument to make Moment use strict parsing. Strict parsing requires that the format and input match exactly, including delimeters
require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
1You can use both locale and strictness
require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
2Strict parsing is frequently the best parsing option. For more information about choosing strict vs forgiving parsing, see the
Parsing two digit years
By default, two digit years above 68 are assumed to be in the 1900's and years 68 or below are assumed to be in the 2000's. This can be changed by replacing the
moment[String];
34 method. The only argument of this method is a string containing the two years input by the user, and should return the year as an integerrequire.config[{
config: {
moment: {
noGlobal: true
}
}
}];
3Parsing glued hour and minutes
From version 2. 11. 0 parsing
moment[String];
35, moment[String];
36, moment[String];
37 and moment[String];
38 is supportedrequire.config[{
config: {
moment: {
noGlobal: true
}
}
}];
41. 0. 0+
chỉnh sửarequire.config[{
config: {
moment: {
noGlobal: true
}
}
}];
5If you don't know the exact format of an input string, but know it could be one of many, you can use an array of formats
This is the same as , only it will try to match the input to multiple formats
require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
6Starting in version 2. 3. 0, Moment uses some simple heuristics to determine which format to use. In order
- Prefer formats resulting in dates over invalid ones
- 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];
31. 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];
82. 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"];
21. 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ệ
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ớimoment[String];
62 [xem bên dưới];moment[String];
64. An invalid month name, such asmoment[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àomoment[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. Booleanmoment[String];
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
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ảngmoment[String];
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ệ
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ạngmoment[String];
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ệ
81moment[String];
82moment[String];
83moment[String];
84moment[String];
85moment[String];
86moment[String];
87moment[String];
88moment[String];
89moment[String];
90moment[String];
91moment[String];
92moment[String];
Sau đây tạo ra một phiên bản bản địa hóa của
moment[String];
93
94 kết quả làmoment[String];
95 ở địa phương hiện tạimoment[String];
96moment[String];
97moment[String];
98moment[String];
99moment[String];
00var day = moment["1995-12-25"];
01var day = moment["1995-12-25"];
02 [Trước 2. 18. 0]var day = moment["1995-12-25"];
03var day = moment["1995-12-25"];
Sự trở lại sau
var day = moment["1995-12-25"];
04
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"];
21var day = moment["1995-12-25"];
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úc
24 returns null, as all other named gettersvar day = moment["1995-12-25"];
25var day = moment["1995-12-25"];
26 has all values set tovar day = moment["1995-12-25"];
23var day = moment["1995-12-25"];
28 returns an invalid Date objectvar day = moment["1995-12-25"];
29 returns nullvar day = moment["1995-12-25"];
30 returns nullvar day = moment["1995-12-25"];
31 returns nullvar day = moment["1995-12-25"];
02 returns null [As of 2. 18. 0]var day = moment["1995-12-25"];
1. 0. 0+
chỉnh sửavar day = moment["1995-12-25"];
6Mutates the original moment by adding time
This is a pretty robust function for adding time to an existing moment. To add time, pass the key of what time you want to add, and the amount you want to add
var day = moment["1995-12-25"];
7There are some shorthand keys as well if you're into that whole brevity thing
var day = moment["1995-12-25"];
8KeyShorthandyearsyquartersQmonthsMweekswdaysdhourshminutesmsecondssmillisecondsmsIf you want to add multiple different keys at the same time, you can pass them in as an object literal
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 years
If 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]
5Trước phiên bản 2. 8. 0, cú pháp
var day = moment["1995-12-25"];
33 cũng được hỗ trợ. 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 khi các giá trị thập phân được chuyển cho ngày và tháng, chúng được làm tròn thành số nguyên gần nhất. 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]
71. 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
1Kể từ phiên bản 2. 0. 0,
var day = moment["1995-12-25"];
35 replaced var day = moment["1995-12-25"];
36Ghi chú.
var day = moment["1995-12-25"];
37 đã được thêm vào trong phiên bản 2. 0. 0Kể từ phiên bản 2. 1. 0,
var day = moment["1995-12-25"];
37 uses the locale aware week start dayGhi chú.
var day = moment["1995-12-25"];
39 đã được thêm vào trong phiên bản 2. 2. 0Ghi chú.
var day = moment["1995-12-25"];
40 đã được thêm làm bí danh cho ngày thứ 2. 13. 02. 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
2Nhận hoặc đặt phần bù UTC sau vài phút
Ghi chú. Không giống như hàm này trả về phần bù thực từ UTC, không phải phần bù ngược [như được trả về bởi
var day = moment["1995-12-25"];
42]Lấy
var day = moment["1995-12-25"];
43 của đối tượng hiện tại2013-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
3Đặt phần bù UTC bằng cách cung cấp số phút. Phần bù được đặt trên đối tượng thời điểm mà
var day = moment["1995-12-25"];
44 được gọi trên. Nếu bạn muốn đặt phần bù trên toàn cầu, hãy thử sử dụng múi giờ. Lưu ý rằng khi bạn đặt giá trị bù, giá trị đó sẽ cố định và sẽ không tự thay đổi [i. e không có quy tắc DST]. Nếu bạn muốn một múi giờ thực tế -- thời gian ở một địa điểm cụ thể, chẳng hạn như var day = moment["1995-12-25"];
45, hãy xem xét múi giờ-thời điểm2013-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
4Nếu thông tin đầu vào nhỏ hơn
var day = moment["1995-12-25"];
46 và lớn hơn var day = moment["1995-12-25"];
47, thay vào đó, nó sẽ diễn giải thông tin đầu vào của bạn dưới dạng số giờ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
5Cũng có thể đặt độ lệch UTC từ một chuỗ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
6moment[String];
55 sẽ tìm kiếm chuỗi cho trận đấu cuối cùng của var day = moment["1995-12-25"];
49, vì vậy bạn thậm chí có thể chuyển một chuỗi được định dạng ISO8601 với độ lệch và thời điểm sẽ được thay đổi thành độ lệch UTC đóLưu ý rằng nếu chuỗi không bao gồm 'Z', nó phải bao gồm ký tự
var day = moment["1995-12-25"];
50 hoặc var day = moment["1995-12-25"];
512013-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
7Hàm
var day = moment["1995-12-25"];
43 có tham số thứ hai tùy chọn chấp nhận giá trị boolean cho biết có nên giữ thời gian hiện có trong ngày hay khôngVượt qua
04 [mặc định] sẽ giữ nguyên thời gian trong Giờ quốc tế, nhưng giờ địa phương sẽ thay đổivar day = moment["1995-12-25"];
Vượt qua
54 sẽ giữ nguyên giờ địa phương, nhưng phải trả giá bằng việc chọn một điểm khác trong Giờ quốc tếvar day = moment["1995-12-25"];
Một cách sử dụng tính năng này là nếu bạn muốn xây dựng một khoảnh khắc với độ lệch múi giờ cụ thể chỉ bằng các giá trị đầu vào số
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
81. 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
9Đây là tùy chọn hiển thị mạnh mẽ nhất. Nó nhận một chuỗi mã thông báo và thay thế chúng bằng các giá trị tương ứng
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 12Mùng 1 Mùng 2. ngày 11 ngày 12MM01 02. 11 12MMMJan Feb. Tháng 11 Tháng 12MMMMTháng 1 Tháng 2. Tháng 11 Tháng 12 Quý 1 Quý 2 3 Quý 4 Quý 2 Ngày 3 Ngày 4 Tháng 1 2. 30 31Do1thứ 2. 30 ngày 31DD01 02. 30 31 Ngày trong năm DD1 2. 364 365DDDo 1st 2nd. 364th 365thDDDD001 002. 364 365Ngày trong tuần0 1. 5 6do0th 1. 5th 6ddSu Mo. Cha SadddChủ Nhật. Thứ Sáu SatddddChủ Nhật Thứ Hai. Thứ sáu Thứ bảyNgày trong tuần [Ngôn ngữ]e0 1. 5 6Ngày trong tuần [ISO]E1 2. 6 7Tuần trong nămw1 2. 52 53wo1thứ 2. thứ 52 thứ 53ww01 02. 52 53Tuần trong năm [ISO]W1 2. 52 53Wo1st 2nd. Thứ 52 Thứ 53WW01 02. 52 53NămYY70 71. 29 30YYYY1970 1971. 2029 2030YYYYYY-001970 -001971. +001907 +001971Ghi chú. [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 24Phút0 1. 58 59mm00 01. 58 59Giây0 1. 58 59ss00 01. 58 59Phân Số GiâyS0 1. 8 9SS00 01. 98 99SSS000 001. 998 999SSSS. SSSSSSSSS000[0. ] 001[0. ]. 998[0. ] 999[0. ] Múi giờ hoặc xe zEST. MST PST
Ghi chú. kể từ 1. 6. 0, mã thông báo định dạng z/zz không được dùng nữa từ các đối tượng thời điểm đơn giản. Đọc thêm về nó ở đây. Tuy nhiên, chúng *làm* hoạt động nếu bạn đang sử dụng một múi giờ cụ thể với addon múi giờ-thời điểm. Z-07. 00 -06. 00. +06. 00 +07. 00ZZ-0700 -0600. +0600 +0700Dấu thời gian UnixX1360013296Dấu thời gian Unix Millisecondpx1360013296123
require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
50 đã được thêm vào 2. 0. 0var day = moment["1995-12-25"];
56 đã được thêm vào 2. 1. 0require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
52 đã được thêm vào 2. 8. 4moment[String];
16 đến var day = moment["1995-12-25"];
59 đã được thêm vào 2. 10. 5. Chúng hiển thị 3 chữ số có nghĩa và phần còn lại chứa đầy số khôngvar day = moment["1995-12-25"];
60 và var day = moment["1995-12-25"];
61 đã được thêm vào 2. 13. 0Định dạng bản địa hóa
Vì định dạng ưa thích khác nhau dựa trên ngôn ngữ, nên có một số mã thông báo có thể được sử dụng để định dạng một khoảnh khắc dựa trên ngôn ngữ của nó
Có các biến thể chữ hoa và chữ thường trên cùng một định dạng. Phiên bản chữ thường được dự định là phiên bản rút gọn của đối tác chữ hoa của nó
Thời gianLT8. 30 PM Thời gian tính bằng giây LTR8. 30. 25 giờ chiềuSố tháng, ngày tháng, nămL09/04/1986l9/4/1986Tên tháng, ngày tháng, nămLL 4/9/1986ll4/9/1986Tên tháng, ngày tháng, năm, giờLL 4/9/1986 8. 30 PMlllNgày 4 tháng 9 năm 1986 8. 30 giờ chiềuTên tháng, ngày trong tháng, ngày trong tuần, năm, giờLLLLThứ năm, ngày 4 tháng 9 năm 1986 8. 30 PMllllThu, ngày 4 tháng 9 năm 1986 8. 30 giờ tốivar day = moment["1995-12-25"];
62 có sẵn trong 2. 0. 0. require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
78 đã được thêm vào 2. 8. 4Nhân vật trốn thoát
Để thoát các ký tự trong chuỗi định dạng, bạn có thể đặt các ký tự trong dấu ngoặc vuông
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
1Điểm tương đồng và khác biệt với LDLML
Ghi chú. Mặc dù các định dạng ngày này rất giống với định dạng ngày của LDML, nhưng có một số khác biệt nhỏ liên quan đến ngày trong tháng, ngày trong năm và ngày trong tuần
Để biết chi tiết về một số mã thông báo định dạng ngày khác nhau trên các ngôn ngữ khác nhau, hãy xem
tốc độ định dạng
Để so sánh Khoảnh khắc. js so với các thư viện khác, hãy xem phần so sánh này với các thư viện khác
Các mã thông báo khác
Nếu bạn cảm thấy thoải mái hơn khi làm việc với strftime thay vì mã thông báo phân tích cú pháp giống như LDML, bạn có thể sử dụng plugin của Ben Oakes. benjaminoakes/khoảnh khắc
định dạng mặc định
Gọi
require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
29 không có định dạng sẽ mặc định là var day = moment["1995-12-25"];
65. Ngoài hộp, var day = moment["1995-12-25"];
65 là định dạng ISO8601 var day = moment["1995-12-25"];
67Kể từ phiên bản 2. 13. 0, khi ở chế độ UTC, định dạng mặc định được điều chỉnh bởi
var day = moment["1995-12-25"];
68 có định dạng var day = moment["1995-12-25"];
69. Điều này trả về require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
26 làm phần bù, thay vì var day = moment["1995-12-25"];
71Trong một số trường hợp nhất định, múi giờ địa phương [chẳng hạn như
var day = moment["1995-12-25"];
72] có thể có độ lệch bằng 0 và sẽ được coi là UTC. Trong những trường hợp như vậy, có thể hữu ích khi đặt var day = moment["1995-12-25"];
65 và var day = moment["1995-12-25"];
68 để sử dụng cùng một định dạngThay đổi giá trị của
var day = moment["1995-12-25"];
65 sẽ chỉ ảnh hưởng đến định dạng và sẽ không ảnh hưởng đến phân tích cú pháp. Ví dụ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
21. 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
3Một cách phổ biến để hiển thị thời gian được xử lý bởi
var day = moment["1995-12-25"];
76. Điều này đôi khi được gọi là timeago hoặc thời gian tương đối2013-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
4Nếu bạn vượt qua
var day = moment["1995-12-25"];
54, bạn có thể nhận được giá trị mà không cần hậu tố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
5Các chuỗi cơ sở là. Thời gian được làm tròn đến giây gần nhất
Bảng phân tích chuỗi nào được hiển thị trong mỗi khoảng thời gian được nêu trong bảng bên dưới
RangeKeySample Output0 đến 44 giâysa vài giây trướcunsetss44 giây trước45 đến 89 giâyma phút trước90 giây đến 44 phútmm2 phút trước. 44 phút trước45 đến 89 phútshan giờ trước90 phút đến 21 giờhh2 giờ trước. 21 giờ trước22 đến 35 giờda ngày trước36 giờ đến 25 ngàydd2 ngày trước. 25 ngày trước26 đến 45 ngàyMa tháng trước45 đến 319 ngàyMM2 tháng trước. 10 tháng trước320 tới 547 ngày [1. 5 năm] hoặc năm trước 548 ngày+yy2 năm trước. 20 năm trướcGhi chú. Từ 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
Ghi chú. Khóa
var day = moment["1995-12-25"];
78 đã được thêm vào trong 2. 18. 0. Đó là một ngưỡng tùy chọn. Nó sẽ không bao giờ hiển thị TRỪ KHI người dùng đặt ngưỡng ss theo cách thủ công. Cho đến khi ngưỡng var day = moment["1995-12-25"];
78 được đặt, nó sẽ mặc định là giá trị của ngưỡng var day = moment["1995-12-25"];
80 trừ đi 1 [do đó, người dùng không nhìn thấy được]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
6Một cách phổ biến để hiển thị thời gian được xử lý bởi
var day = moment["1995-12-25"];
81. Điều này đôi khi được gọi là timeago hoặc thời gian tương đốiĐiều này tương tự với , nhưng cho khoảng ngược lại.
var day = moment["1995-12-25"];
83Điều này tương tự với , nhưng là trường hợp đặc biệt cho thời điểm hiện tại. Sử dụng
var day = moment["1995-12-25"];
84, nếu bạn muốn kiểm soát hai điểm cuối của khoảng thời gian2013-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
7Nếu bạn vượt qua
var day = moment["1995-12-25"];
54, bạn có thể nhận giá trị mà không cần tiền tố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
8Các chuỗi cơ sở là
Bảng phân tích chuỗi nào được hiển thị trong mỗi khoảng thời gian được nêu trong bảng bên dưới
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. trong 25 ngày26 đến 45 ngàyTối thiểu một tháng45 đến 319 ngàyMMTối thiểu 2 tháng. 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 tương ứng với 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
1Ghi chú. Từ phiên bản 2. 25. 0, bạn chỉ có thể truyền đối số định dạng, nó có thể là đối tượng của chuỗi và hàm
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
21. 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
3Để có được sự khác biệt tính bằng mili giây, hãy sử dụng
var day = moment["1995-12-25"];
93 giống như bạn sẽ sử dụng 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
4Để có được sự khác biệt trong một đơn vị đo lường khác, hãy chuyển phép đo đó làm đối số thứ hai
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
5Để có được khoảng thời gian chênh lệch giữa hai khoảnh khắc, bạn có thể chuyển
var day = moment["1995-12-25"];
95 làm đối số thành var day = moment["1995-12-25"];
96. Xem các tài liệu trên để biết thêm thông tinCác phép đo được hỗ trợ là
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 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]
03. Để dễ phát triển, các dạng số ít được hỗ trợ kể từ 2. 0. 0. Các đơn vị đo lường khác với mili giây có sẵn trong phiên bản 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. Nếu bạn muốn một số dấu phẩy động, hãy chuyển var day = moment["1995-12-25"];
54 làm đối số thứ ba. trước 2. 0. 0, var day = moment["1995-12-25"];
93 trả về một số được làm tròn thành số nguyên gần nhất, không phải số bị cắt bớt2013-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
6Nếu thời điểm này sớm hơn thời điểm bạn chuyển đến
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, giá trị trả về sẽ là số âm2013-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
7Một cách dễ dàng để nghĩ về điều này là thay 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]
08 bằng một toán tử trừ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
8Tháng và năm khác nhau
var day = moment["1995-12-25"];
93 có một số cách xử lý đặc biệt đối với sự khác biệt giữa tháng và năm. Nó được tối ưu hóa để đảm bảo rằng hai tháng có cùng ngày luôn cách nhau một số nguyênVì vậy, ngày 15 tháng 1 đến ngày 15 tháng 2 phải đúng 1 tháng
28/02 đến 28/03 chắc là đúng 1 tháng
Ngày 28 tháng 2 năm 2011 đến ngày 28 tháng 2 năm 2012 phải đúng 1 năm
Xem thêm thảo luận về chênh lệch tháng và năm tại đây
Sự thay đổi khác biệt giữa tháng và năm này được thực hiện trong 2. 0. 0. Kể từ phiên bản 2. 9. 0 diff cũng hỗ trợ đơn vị quý
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
9Kiểm tra xem một khoảnh khắc có trước một khoảnh khắc khác không. Đối số đầu tiên sẽ được phân tích cú pháp như một khoảnh khắc, nếu chưa
moment["not a real date"].isValid[]; // false
0Nế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ị làm tham số thứ hai
Vì tham số thứ hai xác định độ chính xác và không chỉ kiểm tra một giá trị duy nhất, sử dụng ngày sẽ kiểm tra năm, tháng và ngày
moment["not a real date"].isValid[]; // false
1Giống 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]
10 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]
11, bất kỳ đơn vị thời gian nào được hỗ trợ 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]
12 đều được hỗ trợ 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]
13moment["not a real date"].isValid[]; // false
2Nếu không có gì được chuyển đến
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, nó sẽ mặc định là thời điểm hiện tạiGHI CHÚ.
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 có hành vi không xác định và không nên được sử dụng. Nếu mã chạy nhanh, thời điểm được tạo ban đầu sẽ giống với thời điểm được tạo trong is Before để thực hiện kiểm tra, vì vậy kết quả sẽ là var day = moment["1995-12-25"];
04. Nhưng nếu mã chạy chậm hơn, có thể thời điểm được tạo trong is Before có thể đo được sau thời điểm được tạo trong moment[String];
32, vì vậy lệnh gọi sẽ trả về var day = moment["1995-12-25"];
542. 0. 0+
chỉnh sửamoment["not a real date"].isValid[]; // false
3Kiểm tra xem một khoảnh khắc có giống với một khoảnh khắc khác không. Đối số đầu tiên sẽ được phân tích cú pháp như một khoảnh khắc, nếu chưa
moment["not a real date"].isValid[]; // false
4Nế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 nó làm tham số thứ hai
moment["not a real date"].isValid[]; // false
5Khi bao gồm tham số thứ hai, nó sẽ khớp với tất cả các đơn vị bằng hoặc lớn hơn. Đậu vào
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 sẽ kiểm tra 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 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]
21. Vượt 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]
22 sẽ kiểm tra 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 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]
21moment["not a real date"].isValid[]; // false
6Giống 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]
10 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]
13, bất kỳ đơn vị thời gian nào được hỗ trợ 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]
12 đều được hỗ trợ 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]
11moment["not a real date"].isValid[]; // false
2Nếu hai thời điểm có múi giờ khác nhau thì múi giờ của thời điểm đầu tiên sẽ được dùng để so sánh
moment["not a real date"].isValid[]; // false
8GHI CHÚ.
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 có hành vi không xác định và không nên được sử dụng. Nếu mã chạy nhanh, thời điểm được tạo ban đầu sẽ giống với thời điểm được tạo trong isSame để thực hiện kiểm tra, vì vậy kết quả sẽ là var day = moment["1995-12-25"];
54. Nhưng nếu mã chạy chậm hơn, có thể thời điểm được tạo trong isSame có thể đo được sau thời điểm được tạo trong moment[String];
32, vì vậy lệnh gọi sẽ trả về var day = moment["1995-12-25"];
042. 9. 0+
chỉnh sửamoment["not a real date"].isValid[]; // false
9Kiểm tra xem một khoảnh khắc có nằm giữa hai khoảnh khắc khác hay không, tùy ý xem theo tỷ lệ đơn vị [phút, giờ, ngày, v.v.]. Trận đấu là độc quyền. Hai đối số đầu tiên sẽ được phân tích cú pháp dưới dạng khoảnh khắc, nếu chưa được như vậ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'
}]
}];
00Lưu ý rằng thứ tự của hai đối số quan trọng. 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'
}]
}];
02Giống 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]
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 bất kỳ đơn vị thời gian nào được hỗ trợ 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]
12 đều được hỗ trợ 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]
38. Năm, tháng, tuần, isoWeek, ngày, giờ, phút và giâyPhiên bản 2. 13. 0 giới thiệu tính toàn diện. 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ừ. Nếu tham số bao gồm được sử dụng, cả hai chỉ số phải được thông qua// 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'
}]
}];
03Lưu ý rằng trong trường hợp các tham 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]
41 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]
42 giống nhau, nhưng các tham số bao gồm khác nhau, sai sẽ chiếm ưu 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'
}]
}];
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]
431. 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. Some time changes in a zone are DST related, some are not, and without complete timezone information it can't know
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'
}]
}];
061. 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'
}]
}];
07By default, Moment. 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
To load a locale, pass the key and the string values 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]
45More details on each of the parts of the locale bundle can be found in the section
// 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'
}]
}];
08Details about
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 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]
47 can be found in the sectionOnce you load a locale, it becomes the active locale. To change active locales, simply call
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 with the key of a loaded locale// 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'
}]
}];
09As of 2. 21. 0, Moment will
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 if the locale is unavailableAs of 2. 8. 0, changing the global locale doesn't affect existing instances
// 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 returns the locale used. This is useful because Moment won't change locales if it doesn't know the one you specify// 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'
}]
}];
11You may also specify a list of locales, and Moment will use the first one it has localizations for
// 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 will also try locale specifier substrings from most-specific to least-specific until it finds a locale it knows. This is useful when supplying Moment with a locale string pulled from the user's environment, such as
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'
}]
}];
13Finally, Moment will search intelligently through an array of locales and their substrings
// 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'
}]
}];
14The logic works as follows -- the next locale is picked and tried as-is. If that fails, the code normally tries to chop the last bit [normally the country designation] and try again. However, if the next array element has the same or longer prefix as the one to be tried, the iteration continues. So for example if the array has the sequence
// 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'
}]
}];
15then first "AA-BB" is tried, then a naive solution would try "AA", but this one instead checks to see that "AA-CC" is actually more concrete than "AA", so it tries "AA-CC" next, and only after it fails [if it fails] it tries "AA", because "XX-YY" does not have "AA" as prefix. So in the end the following locales are tried in this order [assuming all fail so the next one is tried]
// 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'
}]
}];
161. 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'
}]
}];
17A global locale configuration can be problematic when passing around moments that may need to be formatted into different locale
// 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'
}]
}];
18If you call
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 with no parameters, you get back the locale configuration that would be used for that moment// 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'
}]
}];
19If you need to access the locale data for a moment, this is the preferred way to do so
As of 2. 3. 0, you can also specify an array of locale identifiers. It works the same way it does in the
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'
}]
}];
20It is sometimes useful to get the list of months or weekdays in a locale, for example when populating a dropdown menu
// 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'
}]
}];
21Returns the list of months in the current locale
// 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'
}]
}];
22Similarly,
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 returns abbreviated month names, 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]
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 return lists of weekdaysYou can pass an integer into each of those functions to get a specific month or weekday
// 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'
}]
}];
23As of 2. 13. 0 you can pass a bool as the first parameter of the weekday functions. If true, the weekdays will be returned in locale specific order. For instance, in the Arabic locale, Saturday is the first day of the week, thus
// 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'
}]
}];
24Note. Absent the locale specific parameter, weekdays always have Sunday as index 0, regardless of the local first day of the week
Some locales make special considerations into account when formatting month names. For example, Dutch formats month abbreviations without a trailing period, but only if it's formatting the month between dashes. The
var day = moment["1995-12-25"];
98 method supports passing a format in so that the months will be listed in the proper context// 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'
}]
}];
25And finally, you can combine both the format option and the integer option
// 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'
}]
}];
262. 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'
}]
}];
27You can access the properties of the currently loaded locale through 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]
58 function. It returns the current locale or a locale with the given key// 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'
}]
}];
28The returned object has the following methods
// 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'
}]
}];
29Details about
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 can be found in the sectionMoment. js is very easy to customize. In general, you should create a locale setting with your customizations
// 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'
}]
}];
30You can remove a previously defined locale by passing
moment[String];
69 as the second argument. The deleted locale will no longer be available for use// 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'
}]
}];
31As of 2. 12. 0 it is possible to create a locale that inherits from a parent locale
// 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'
}]
}];
32Properties that are not specified in the locale will be inherited from the parent locale
As of 2. 16. 0 it is possible to define a locale with a parent that hasn't itself been defined or loaded
// 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'
}]
}];
33As of 2. 21. 0 when attempting to create a moment with the newly defined locale, moment will attempt to lazy load the parent if it exists. Failing that it will default the parent to the global locale
As of 2. 12. 0 it is also possible to update a locale's properties
// 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'
}]
}];
34Any properties specified will be updated, while others will remain the same. This function does not affect moments that already exist. Note that calling
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 also changes the current global locale, to the locale that is updated; see this GitHub issue for more informationTo revert an update use
// 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 deprecated using
require.config[{
config: {
moment: {
noGlobal: true
}
}
}];
43 to change an existing locale. Use 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 instead1. 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 should be an array of the month names// 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'
}]
}];
37If you need more processing to calculate the name of the month, [for example, if there is different grammar for different formats],
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 can be a function with the following signature. It should always return a month name// 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'
}]
}];
38From version 2. 11. 0 months can also be an object, specifying
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 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]
67 forms [nominative and accusative]. The regular expression that is run on the format to check whether to use 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]
67 form is 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. From version 2. 14. 0 a different one can be specified with 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]
70 key// 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'
}]
}];
391. 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 should be an array of the weekdays names// 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 can be a callback function as well// 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'
}]
}];
42Note. From version 2. 11. 0 format/standalone cases can be passed as well.
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 will be used against the full format string to determine which form to use// 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'
}]
}];
431. 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 should be an object of the replacement strings for 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 refers to the prefix/suffix for future dates, 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]
77 refers to the prefix/suffix for past dates. For all others, a single character refers to the singular, and a double character refers to the pluralIf a locale requires additional processing for a token, it can set the token as a function with the following signature. The function should return a string
// 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'
}]
}];
46The
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 argument refers to the replacement key in 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]
74 object. [eg. 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, etc. ]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]
81 argument refers to the number of units for that key. 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]
82, the number is the number of minutes, etcThe
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 argument will be true if the token will be displayed without a suffix, and false if it will be displayed with a suffix. [The reason for the inverted logic is because the default behavior is to display with the suffix. ]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]
84 argument will be true if it is going to use the future suffix/prefix and false if it is going to use the past prefix/suffixNote. Handling 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]
85 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]
86 was added in 2. 25. 02. 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. ddaysleast number of days to be considered a week. 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ú. Week unit was added in 2. 25. 0. By default it is not used [set to null], but you can set it to non-null value, and also [optionally] set
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 lower, so it transitions from days to weeks earlierNote. Retrieving thresholds was added in 2. 8. 1
Note. Retrieving and setting
var day = moment["1995-12-25"];
78 threshold was added in 2. 18. 01. 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 should be an integer representing the first day of the week, 0 is Sunday, 1 is Monday, . , 6 is Saturday2013-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 should be an integer. 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 is used together with 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 to determine the first week of the year. 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 is calculated as 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, where 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 is the first day of January that must belong to the first week of the year// 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'
}]
}];
502. 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'
}]
}];
51Specify Eras for a particular locale. An era is a time interval with name and year numbering. Absolute year number [like 2020] can also be specified as 2020 AD. the 2020th year of the era AD. Similarly the absolute year number -0500 can be described as 501 BC, the 501st year from the BC era
// 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 and 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 govern the direction of the era. As in the case of 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 it grows toward 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, thus 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. For eras that increment toward +Infinity 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
06Parsing/formatting of eras is accomplished with
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 and 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
15 tokensNote. The era-related APIs are subject to change
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'
}]
}];
53To create a duration, call
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 with the length of time in milliseconds// 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'
}]
}];
54If you want to create a moment with a unit of measurement other than milliseconds, you can pass the unit of measurement as well
// 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'
}]
}];
55The same shorthand for
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 and 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 works here as wellKeyShorthandyearsymonthsMweekswdaysdhourshminutesmsecondssmillisecondsmsMuch like
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, you can pass an object of values if you need multiple different units of measurement// 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'
}]
}];
56As of 2. 1. 0, moment supports parsing ASP. NET style time spans. The following formats are supported
The format is an hour, minute, second string separated by colons like
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. The number of days can be prefixed with a dot separator like so 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. Partial seconds are supported as well 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'
}]
}];
57As of 2. 3. 0, moment also supports parsing durations
// 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'
}]
}];
58As of 2. 11. 0, duration format strings with a space between days and rest is supported
// 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'
}]
}];
59As of 2. 13. 0, mixed negative and positive signs are supported when parsing durations
// 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'
}]
}];
60As of 2. 18. 0, invalid durations are supported, similarly to invalid moments. To create an invalid duration you can pass
var day = moment["1995-12-25"];
23 for a value of a unitIn upcoming releases expect invalid durations to cover more cases [like null values for units]
// 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'
}]
}];
611. 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'
}]
}];
62Sometimes, you want all the goodness of
var day = moment["1995-12-25"];
94 but you don't want to have to create two moments, you just want to display a length of timeEnter
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'
}]
}];
63By default, the return string is describing a duration
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 [suffix-less]. If you want an oriented duration 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 [with suffix], pass in true as seen below// 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'
}]
}];
64For suffixes before now, pass in a negative number
// 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'
}]
}];
65Invalid durations are humanized to the localized version of
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. To specify thresholds for a particular invocation of humanize, pass them as a sole argument or after suffix arg