Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 콜백함수
- 인라인블럭
- first-child
- react redux
- 블럭요소
- useParams
- JSON
- 협업프로젝트
- foreach
- javascript코딩테스트
- redux toolkit
- useSearchParams
- 자바스크립트
- useEffect
- sort
- react
- 자바스크립트배포
- toString
- Redux store
- 카우치코딩
- 6주포트폴리오
- redux 사용방법
- couchcoding
- React state
- JavaScript
- Redux
- React onClick
- db.json
- line-through
- javascript React
Archives
- Today
- Total
개발하는 루루언니
timeago.js 라이브러리를 이용해 몇시간전.. 구현하기 본문
728x90
반응형
✅ timeago.js 라이브러리는 내가 작성한 글을 등록했을때 디테일한 부분보단 방금전,한시간전 이런식으로
UI에 보여줄 수 있는 간편한 라이브러리 이다. :)
https://www.npmjs.com/package/timeago.js/v/4.0.0-beta.3
timeago.js
timeago.js is a simple library (only 1kb) to used to format datetime with `*** time ago` statement. eg: '3 hours ago'. localization supported.. Latest version: 4.0.2, last published: 3 years ago. Start using timeago.js in your project by running `npm i tim
www.npmjs.com
api로 데이터를 가져왔을때는 날짜부터 디테일한 부분이 표시가 되는데 위의 방법보단 6개월 전이 훨씬 보기가 좋다
그리고 한국어이다 :)
✅ 라이브러리 사용해보기
1. npm 설치
2. import 해주기
import { format, render, cancel, register } from 'timeago.js';
// or
import * as timeago from 'timeago.js';
3. 한국어로 표시되게 하고 싶다면?
import koLocale from 'timeago.js/lib/lang/ko'
register('ko',koLocale)
<p>{format(publishedAt,'ko')}</p>
위와 같이 설정을 해주면 한국어로 표시가 된다.
728x90
'컴퓨터 정보 > 리액트' 카테고리의 다른 글
react : 스크롤 감지 이벤트 (0) | 2023.06.20 |
---|---|
React 폴더구조 (0) | 2023.06.02 |
리액트 : 이미지 업로드 미리보기 (0) | 2023.04.04 |
React : 커스텀 hook 을 사용해보자 :) (0) | 2023.04.03 |
React : ✅ token 을가져와 url로 로그인 해보기 (0) | 2023.03.17 |