欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Moment.js常見用法總結(jié)

 更新時間:2022年05月03日 14:32:05   作者:荒男  
這篇文章主要介紹了Moment.js常見用法總結(jié),需要的朋友可以參考下

Moment.js是一個輕量級的js時間處理類庫,其使用簡單,方便了日常開發(fā)中對時間的操作,提高了開發(fā)效率。

引用Moment.js

npm install moment

常用的方法

1、moment()

獲取當(dāng)前的日期和時間

moment()

獲取String的日期和時間

moment(String)

2、獲取get

獲取當(dāng)天的年份

moment().get('year')

獲取當(dāng)天的月份 0-11

moment().get('month')

獲取當(dāng)天的日期

moment().get('date')

3、格式format

得到的時間格式為YYYY-MM-DD

moment(String,'YYYY-MM-DD')
moment(String).format('YYYY-MM-DD')

4、設(shè)置subtract

.subtract(Number, String);

設(shè)置年份,,獲取一年前的時間

moment().subtract(1, 'years')

設(shè)置月份,獲取一個月前的時間

moment().subtract(1, 'months')

設(shè)置日期,獲取昨天的時間

moment().subtract(1, 'days')

5、開始startOf()

通過將原始的 moment 設(shè)置為時間單位的開頭來對其進(jìn)行更改。

.startOf(String);

獲取今天的0時0分0秒

moment().startOf('day')

獲取本周第一天的0時0分0秒

moment().startOf('week')

6、結(jié)束endOf()

通過將原始的 moment 設(shè)置為時間單位的末尾來對其進(jìn)行更改

.endOf(String);

獲取今天的23時59分59秒

moment().endOf('day')

獲取本周第一天的23時59分59秒

moment().endOf('week')

7、總天數(shù)Days in Month

.daysInMonth()

獲取2月的天數(shù)。

moment("2012-02", "YYYY-MM").daysInMonth() // 29

8、時間戳

.unix() //秒數(shù)

.valueOf() //毫秒數(shù)

獲取時間戳(以秒為單位)

moment().format('X').unix() // 返回值為數(shù)值型

獲取時間戳(以毫秒為單位)

moment().format('x').valueOf() // 返回值為數(shù)值型

9、關(guān)于ant選擇時間的實戰(zhàn)

在ant的a-range-picker組件的disabledDate使用

在這里插入圖片描述

不能選擇今天之前的日期(包括今天)

disabledDate(current) {
     return current && current < moment().endOf('day');
},

不能選擇今天之前的日期(不包括今天)

disabledDate(current) {
   return current && current < moment().subtract(1, 'days').endOf('day')
},

點擊選擇的2019-01-01之前的數(shù)據(jù)無法確認(rèn)

disabledDate(current) {
	return current  && current < moment('2019-01-01') 
},

 

相關(guān)文章

最新評論