JS Dates Notes Posted on 2018-05-13 Edited on 2020-01-01 JS Dates NotesTerms GMT: Greenwich Mean Time UTC: Coordinated Universal Time GMT ≈ UTC (≒) CST: Central Standard Time Format: ISO Date YYYY-MM-DDTHH:MM:SSZ YYYY-MM-DD YYYY-MM YYYY 1234567891011121314151617// NowDate.now() // 1526128945300// Nownew Date() // Sat May 12 2018 20:37:57 GMT+0800 (CST)// The ISO 8601 syntax (YYYY-MM-DD)new Date('2016-11-18') // Fri Nov 18 2016 08:00:00 GMT+0800 (CST)new Date('2019-05-18') // Sat May 18 2019 08:00:00 GMT+0800 (CST)// input:「12:37:57(+0000)」 return:「20:37:57(+0800)」new Date('2018-05-12T12:37:57Z') // Sat May 12 2018 20:37:57 GMT+0800 (CST)// input:「21:37:57(+0900)」 return:「20:37:57(+0800)」new Date('2018-05-12T21:37:57+09:00') // Sat May 12 2018 20:37:57 GMT+0800 (CST)new Date('2018-05-12T12:37:57Z').toDateString() // "Sat May 12 2018"new Date('2018-05-12T12:37:57Z').toUTCString() // "Sat, 12 May 2018 12:37:57 GMT" Substract two dates1234567891011121314var a = new Date('2016-11-18')var b = new Date('2019-05-18')// samevar diff = Math.abs(b - a); // msvar diff = Math.abs(b.getTime() - a.getTime()); // ms// get diff daysvar diffDays = Math.ceil(diff / (1000 * 3600 * 24)); // one line: get days(new Date('2019-11-02') - new Date('2019-08-17'))/1000/60/60/24// one line: get months (approximately equal)(new Date('2019-05-18') - new Date('2016-11-18'))/1000/60/60/24/30.42 Add/Substract days123var today = new Date()today.setDate(today.getDate() - 365)console.log(today)