대상 moment 객체의 date가 인자로 넣은 moment 객체의 date와 얼마나 차이나는지를 출력
diff(moment_객체, 형식)
두 moment 객체 간의 차이 비교
사용 예시
constdateB=moment('2014-11-11');constdateC=moment('2014-10-11');console.log('Difference is ',dateB.diff(dateC),'milliseconds');//인자가 없으면 기본 단위인 milliseconds 사용console.log('Difference is ',dateB.diff(dateC,'days'),'days');console.log('Difference is ',dateB.diff(dateC,'months'),'months');
1
2
3
4
5
6
7
8
9
10
- 날짜 비교
- isBefore(날짜)
- 대상 moment 객체가 가진 date가 인자로 넣은 date보다 이전이면 true 반환
- isAfter(날짜)
- 대상 moment 객체가 가진 date가 인자로 넣은 date보다 이후라면 true 반환
- isAfter(날짜)
- 대상 moment 객체가 가진 date가 인자로 넣은 date보다 같다면 true 반환
- isLeapYear()
- 대상 moment 객체가 가진 date가 윤년이면 true 반환 - 사용 예시
- Format Dates
moment().format('MMMM Do YYYY, h:mm:ss a');// 12월 22일 2023, 2:40:27 오후moment().format('dddd');// 금요일moment().format("MMM Do YY");// 12월 22일 23moment().format('YYYY [escaped] YYYY');// 2023 escaped 2023moment().format();// 2023-12-22T14:40:27+09:00
1
- Relative Time
moment("20111031","YYYYMMDD").fromNow();// 12년 전moment("20120620","YYYYMMDD").fromNow();// 12년 전moment().startOf('day').fromNow();// 15시간 전moment().endOf('day').fromNow();// 9시간 후moment().startOf('hour').fromNow();// 41분 전
1
- Calendar Time
moment().subtract(10,'days').calendar();// 2023.12.12.moment().subtract(6,'days').calendar();// 지난주 토요일 오후 2:40moment().subtract(3,'days').calendar();// 지난주 화요일 오후 2:40moment().subtract(1,'days').calendar();// 어제 오후 2:40moment().calendar();// 오늘 오후 2:40moment().add(1,'days').calendar();// 내일 오후 2:40moment().add(3,'days').calendar();// 월요일 오후 2:40moment().add(10,'days').calendar();// 2024.01.01.
1
- Multiple Locale Support
moment.locale();// komoment().format('LT');// 오후 2:40moment().format('LTS');// 오후 2:40:46moment().format('L');// 2023.12.22.moment().format('l');// 2023.12.22.moment().format('LL');// 2023년 12월 22일moment().format('ll');// 2023년 12월 22일moment().format('LLL');// 2023년 12월 22일 오후 2:40moment().format('lll');// 2023년 12월 22일 오후 2:40moment().format('LLLL');// 2023년 12월 22일 금요일 오후 2:40moment().format('llll');// 2023년 12월 22일 금요일 오후 2:40