当前位置:网站首页>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
边栏推荐
- 572. 另一个树的子树
- Deployment of Flink
- A multi classification model suitable for discrete value classification -- softmax regression
- Error code in ijkplayer
- PHP processing tree and infinite processing
- 箭头函数的this指向
- How to treat the ethical issues arising from driverless Technology
- PHP laravel8 send email
- The difference between call and apply and bind
- Servlet
猜你喜欢

Simple knapsack problem

Who is stronger, zip or 7-Zip, and how to choose?

FPGA interview topic notes (I) - FPGA development process, metastable state and competitive risk, build and hold time, asynchronous FIFO depth, etc

通过R语言且只用基础package来制作一个小游戏

jenkins-凭证管理

PHP laravel8 send email

Shandong University machine learning experiment 5 SVM

山东大学项目实训之examineListActivity

Jenkins different styles of project construction

Deployment of Flink
随机推荐
The difference between call and apply and bind
FPGA Design -- ping pong operation implementation and Modelsim simulation
Detailed installation instructions for MySQL
Transfer Learning
[reading this article is enough!!! Easy to understand] confidence level understanding (95% confidence level and confidence interval)
Use meshlab to sample the point cloud of CAD model and display it in PCL
Who is stronger, zip or 7-Zip, and how to choose?
go的fmt包使用和字符串的格式化
QT socket设置连接超时时间
CCS method of installing compiler
懒加载,预加载
Sqoop installation tutorial
Quantitative understanding (Quantitative deep revolutionary networks for effective information: a whitepaper)
572. 另一个树的子树
Basic use of BufferedReader and bufferedwriter
Analyze the principle of configuration center from the perspective of Nacos client
Handwriting promise [02] - asynchronous logic implementation
ERROR 1215 (HY000): Cannot add foreign key constraint
FPGA面试题目笔记(三)——跨时钟域中握手信号同步的实现、任意分频、进制转换、RAM存储器等、原码反码和补码
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