2016년 10월 11일 화요일

Moment.js 간편한 JavaScript 날짜 시간 연산 라이브러리

Moment.js

날짜, 시간 연산 할 때는 순수 자바스크립트 말고 Moment.js를 씁시다.


연산 예시

moment('2016-01-01').add(1, 'year').format('LL')
"January 1, 2017"
moment('2016-01-01').add(365, 'day').format('LL')
"December 31, 2016"

2016년은 윤년이므로 두 예시의 차이가 있다.


날짜 시간 표현

  • English
moment.locale('en');
moment().format('LT');   // 11:42 PM
moment().format('LTS');  // 11:42:14 PM
moment().format('L');    // 10/11/2016
moment().format('l');    // 10/11/2016
moment().format('LL');   // October 11, 2016
moment().format('ll');   // Oct 11, 2016
moment().format('LLL');  // October 11, 2016 11:42 PM
moment().format('lll');  // Oct 11, 2016 11:42 PM
moment().format('LLLL'); // Tuesday, October 11, 2016 11:42 PM
moment().format('llll'); // Tue, Oct 11, 2016 11:42 PM
  • 한국어
moment.locale('ko');
moment().format('LT');   // 오후 11시 42분
moment().format('LTS');  // 오후 11시 42분 57초
moment().format('L');    // 2016.10.11
moment().format('l');    // 2016.10.11
moment().format('LL');   // 2016년 10월 11일
moment().format('ll');   // 2016년 10월 11일
moment().format('LLL');  // 2016년 10월 11일 오후 11시 42분
moment().format('lll');  // 2016년 10월 11일 오후 11시 42분
moment().format('LLLL'); // 2016년 10월 11일 화요일 오후 11시 42분
moment().format('llll'); // 2016년 10월 11일 화 오후 11시 42분

댓글 없음:

댓글 쓰기