亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

引用Moment.js

npm install moment

常用的方法

1、moment()

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

moment()

獲取String的日期和時(shí)間

moment(String)

2、獲取get

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

moment().get('year')

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

moment().get('month')

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

moment().get('date')

3、格式format

得到的時(shí)間格式為YYYY-MM-DD

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

4、設(shè)置subtract

.subtract(Number, String);

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

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

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

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

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

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

5、開始startOf()

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

.startOf(String);

獲取今天的0時(shí)0分0秒

moment().startOf('day')

獲取本周第一天的0時(shí)0分0秒

moment().startOf('week')

6、結(jié)束endOf()

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

.endOf(String);

獲取今天的23時(shí)59分59秒

moment().endOf('day')

獲取本周第一天的23時(shí)59分59秒

moment().endOf('week')

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

.daysInMonth()

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

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

8、時(shí)間戳

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

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

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

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

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

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

9、關(guān)于ant選擇時(shí)間的實(shí)戰(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')
},

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

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

 

相關(guān)文章

最新評論