- MomentJS 教程
- MomentJS - 首頁
- MomentJS - 概覽
- MomentJS - 環境設定
- MomentJS - 介紹
- MomentJS - 解析日期和時間
- MomentJS - 日期驗證
- MomentJS - 獲取器/設定器
- 操作日期和時間
- 格式化日期和時間
- MomentJS - 日期查詢
- MomentJS - 國際化
- MomentJS - 自定義
- MomentJS - 持續時間
- MomentJS - 實用程式
- MomentJS - 外掛
- MomentJS - 示例
- MomentJS 有用的資源
- MomentJS - 快速指南
- MomentJS - 有用的資源
- MomentJS - 討論
MomentJS - 是否在之前
此方法檢查給定的時刻是否在另一個時刻之前。它返回 true 或 false。
語法
moment().isBefore(Moment|String|Number|Date|Array); moment().isBefore(Moment|String|Number|Date|Array, String);
範例
var isbefore = moment().isBefore('2020-10-21');
輸出
注意 isBefore 內部使用的日期大於當前日期,因此我們得到的輸出為 true。
範例
var isbefore = moment([2015, 10, 01]).isBefore([2000, 10, 21]);
輸出
使用 isBefore,我們可以比較從一種時刻到另一種時刻的日期。我們還可以使用 isBefore 指定單位。支援的單位有年、月、周、日、時、分和秒。
範例
讓我們考慮一個使用傳遞給 isBefore() 的單位的工作範例;
var isbefore = moment([2015, 10, 01]).isBefore([2010, 10, 21], 'year');
輸出
momentjs_date_queries.htm
廣告