πŸ“šΒ Reference


πŸ“œΒ Chapter


Day.js

RelativeTimeFormat


νŠΉμ§•


μ‚¬μš© 방법


// 1. 객체 생성 (ν•œκ΅­μ–΄ μ„€μ •)
const rtf = new Intl.RelativeTimeFormat('ko', {
  numeric: 'auto' // 'always'λŠ” "-1일 μ „", 'auto'λŠ” "μ–΄μ œ"둜 ν‘œμ‹œ
});

// 2. ν˜•μ‹ λ§žμΆ”κΈ° (κ°’, λ‹¨μœ„)
console.log(rtf.format(-1, 'day'));    // "μ–΄μ œ"
console.log(rtf.format(1, 'day'));     // "내일"
console.log(rtf.format(-2, 'month'));  // "2달 μ „"
console.log(rtf.format(3, 'year'));    // "3λ…„ ν›„"