공식문서: https://momentjs.com/docs/
좋았던 점
// 현재 날짜 생성
const now = moment();
now.format(); // ex) 2022-04-12T00:01:13+09:00
// 지정 날짜 생성
// !! 지정 포맷(string)이 있을 경우 해당 포맷을 명시해줘야 함
let date = moment('2022.04.12');
date.format(); // ex) 2022-04-12T00:00:00+09:00
date = moment('2022.04.12', 'YYYY.MM.DD');
date.format(); // ex) 2022-04-12T00:00:00+09:00
date = moment('2022/04', 'YYYY/MM');
date.format(); // ex) 2022-04-01T00:00:00+09:00
const now = moment();
now.format(); // ex) 2022-04-12T00:00:00+09:00
now.format('YYYY.MM.DD'); // ex) 2022.04.12
now.format('YY/MM/DD'); // ex) 22/04/12
'years | y', 'months | M', 'days | d'
'hours | h', 'minutes | m', 'seconds | s', 'milliseconds | ms'
const now = moment(); // ex) 2022-04-12T00:00:00+09:00
now.add(1, 'years').format('YYYY.MM'DD'); // ex) 2023.04.12
now.add(1, 'months').format('YYYY.MM'DD'); // ex) 2022.05.12
now.add(1, 'days').format('YYYY.MM'DD'); // ex) 2022.04.13
now.subtract(1, 'years').format('YYYY.MM'DD'); // ex) 2021.04.12
now.subtract(1, 'months').format('YYYY.MM'DD'); // ex) 2022.03.12
now.subtract(1, 'days').format('YYYY.MM'DD'); // ex) 2022.04.11
'years', 'months', 'days', 'hours', 'minutes', 'seconds', 'milliseconds'
const now = moment();
const next = moment('2023-04-13'); // 1년 후
now.diff(next, 'years'); // 1
now.diff(next, 'months'); // 12
하지만 더이상 moment 라이브러리의 업데이트는 진행하지 않는다고 한다.
너무 방대해진 규모, js 흐름에 맞지 않는 단점이 있다고 한다.
그래서 유용한 라이브러리를 사용한 좋은 경험을 한 것 같고 같고 다른 라이브러리(Day.js, Date-fns ...)를 사용해봐야겠다.