- Standard time is converted to Chinese standard time
let date1 = '2019-11-19'; // Standard timeletdata2 = new Date(date1); //date2: Tue Nov 19 2019 08:00:00 GMT+0800Copy the code
- Chinese standard time goes to YYYY-MM-DD
let d = new Date('Tue Nov 19 2019 08:00:00 GMT+0800'); let newTime = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate(); console.log(newTime)// "2019-11-19"Copy the code
- Calculate monthly difference
let d1 = new Date('the 2018-10'); let d2 = new Date('2019-12'); let date1 = parseInt(d1.getFullYear()) * 12 + parseInt(d1.getMonth()+1); let date2 = parseInt(d2.getFullYear()) * 12 + parseInt(d2.getMonth()+1); let newTime = Math.abs(date1 - date2); console.log(newTime)//14 Copy the code
- The time stamp
let result = new Date('2017-09-19').getTime(); console.log(result)//1505779200000Copy the code
- Gets the last day of the month
Var lastDay = new Date (2020,6,0). GetDate ()Copy the code