当前位置:网站首页>Moment time plug-in tips -js (super detailed)
Moment time plug-in tips -js (super detailed)
2022-06-11 06:27:00 【Э Time walker to me】
Let's share one moment Plug in tips
moment Plug in tips
- Let's share one moment Plug in tips
- 1. This month, ( The current month )`YYYY-MM`
- notes :`this.$moment()` Is my main.js Overall , You can also introduce... On demand
- 2. This month, + date `YYYY-MM-DD`
- 3. This year `YYYY-MM`
- 4. This year `YYYY-MM-DD`
- 5. The first seven days `YYYY-MM-DD`
- 6. front 30 God 、 front 60 God 、 front 90 The sky is the same `YYYY-MM-DD`
- 7. Calculate the number of days between two times
1. This month, ( The current month )YYYY-MM
eg:2022-01----2022-01
notes :this.$moment() Is my main.js Overall , You can also introduce... On demand

import Moment from 'moment'
Vue.prototype.$moment = Moment
let date1 = this.$moment().startOf('month').format('yyyy-MM')
let date2 = this.$moment().endOf('month').format('yyyy-MM')
2. This month, + date YYYY-MM-DD
For example, in January 1 The start , End on current date
eg:2022-01-01----2022-01-20

let date1 = this.$moment(new Date()).startOf('month').format('YYYY-MM-DD')
let date2 = this.$moment(new Date()).format('YYYY-MM-DD')
Abbreviation , Negligible new Date()
let date1 = this.$moment().startOf('month').format('YYYY-MM-DD')
let date2 = this.$moment().format('YYYY-MM-DD')
3. This year YYYY-MM
For example, in January of this year 1 The start , To the current year 12 End of the month
eg:2022-01----2022-12

let date1 = this.$moment().startOf('year').format('yyyy-MM')
let date2 = this.$moment().endOf('year').format('yyyy-MM')
4. This year YYYY-MM-DD
For example, in January of this year 1 The start , To the current year 12 month 31 End of the day
eg:2022-01-01----2022-12-31

let date1 = this.$moment().startOf('year').format('yyyy-MM-DD')
let date2 = this.$moment().endOf('year').format('yyyy-MM-DD')
5. The first seven days YYYY-MM-DD
For example, the first seven days of this month
With 20 Column No eg:2022-01-13----2022-01-20
let date1 = this.$moment(new Date()).subtract(7, 'days').format('YYYY-MM-DD')
let date2 = this.$moment(new Date()).format('YYYY-MM-DD')
6. front 30 God 、 front 60 God 、 front 90 The sky is the same YYYY-MM-DD
According to your own needs , You can also write before 2 Months 、 front 3 Months …

front 60 Heaven and earth 20 Column No eg:2021-11-21----2022-01-20
let date1 = this.$moment(new Date()).subtract(60, 'days').format('YYYY-MM-DD')
let date2 = this.$moment(new Date()).format('YYYY-MM-DD')
7. Calculate the number of days between two times

Be careful : The date must be big or small , Otherwise the date will become negative , Unless you need to count down And so on. , That's OK
let startDate = moment('2022-01-01 09:00').format('YYYY-MM-DD')
let endDate = moment('2022-02-01 09:00').format('YYYY-MM-DD')
console.log(' The difference in days is 1-------->', moment(endDate).diff(startDate, 'day')) // 31 God
// Or you can write the following method in one step
let date1 = this.moment('2022-02-01 09:00').diff(this.moment('2022-01-01 09:00'), 'day', true).toFixed(1)
console.log(' The difference in days is 2-------->', date1 ) // 31.0 You can see whether you need a decimal point according to your own needs
边栏推荐
- The difference between call and apply and bind
- 不引入第三个变量,交换两个值
- Build the first power cloud platform
- Ethical discussion on reptile Technology
- Wechat applet (authorized login) (not recommended, click the home page to view the updated authorized login)
- Shandong University machine learning experiment 7 pca+ SVM face recognition
- Super explanation
- Fix the problem that the right mouse button does not have a vscode shortcut
- This point of arrow function
- 617. 合并二叉树
猜你喜欢

Résoudre le problème de la durée inexacte du fichier audio AAC obtenu par ffmpeg

不同VLAN间的通信
![[]==![]](/img/65/ab724c74b080da319ed5c01c93fdb7.png)
[]==![]

FPGA面试题目笔记(二)——同步异步D触发器、静动态时序分析、分频设计、Retiming

Servlet

Shandong University machine learning final 2021

Markdown + typora + picgo experimental report template attached

PHP laravel8 send email

Simple understanding of pseudo elements before and after

MATLAB realizes mean filtering and FPGA for comparison, and uses Modelsim waveform simulation
随机推荐
C语言大战“扫雷”
Difference between foreach, for... In and for... Of
Shandong University machine learning experiment VI k-means
FPGA interview notes (IV) -- sequence detector, gray code in cross clock domain, ping-pong operation, static and dynamic loss reduction, fixed-point lossless error, recovery time and removal time
Warning: Each child in a list should have a unique “key“ prop.
Basic use of BufferedReader and bufferedwriter
Solve the problem that ffmpeg obtains aac audio files with incorrect duration
箭头函数的this指向
Why don't we have our own programming language?
Servlet
Docker installation of MySQL and redis
text-overflow失效
Print sparse arrays and restore
MySQL implements over partition by (sorting the data in the group after grouping)
Verilog realizes binocular camera image data acquisition and Modelsim simulation, and finally matlab performs image display
Handwritten promise [04] - then method chain call to recognize promise object self return
021-MongoDB数据库从入门到放弃
通过两种方式手写一个消息队列
不引入第三个变量,交换两个值
On cursor in MySQL