본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

RelativeTime

원문 보기 위키 갱신

RelativeTime은 시간을 명확하고 간결하며 접근성 있게 표시하는 컴포넌트예요. 이 컴포넌트의 기능은 모두 relative-time-element(GitHub 스태프 전용) 커스텀 엘리먼트에서 비롯됩니다.

출처: 문서

본문

RelativeTime은 시간을 명확하고 간결하며 접근성 있게 표시합니다. React와 Rails 모두 지원됩니다. 이 컴포넌트의 모든 기능은 relative-time-element(GitHub 스태프 전용) 커스텀 엘리먼트에서 나옵니다.

React 예제

기본

<RelativeTime date={new Date('2020-01-02T00:00:00Z')} />

시간과 함께

<RelativeTime second="numeric" minute="numeric" hour="numeric" date={new Date('2020-01-02T01:02:03Z')} />

앞자리 0과 함께

숫자 형식 가이드라인을 참고하세요.

<RelativeTime day="2-digit" second="2-digit" minute="2-digit" hour="2-digit" date={new Date('2020-01-02T01:02:03Z')} />

"on" 접두사 없이

단어 형식 가이드라인을 참고하세요.

<RelativeTime date={new Date('2020-01-02T01:02:03Z')} prefix="" />

마이크로 형식

<RelativeTime format="micro" date={new Date('2020-01-02T01:02:03Z')} />

title 속성 없이

<RelativeTime date={new Date('2020-01-02T01:02:03Z')} noTitle={true} />

툴팁이 있는 링크로

<Tooltip text={new Date('2020-01-02T01:02:03Z').toString()}>
  <Link href="#">
    <RelativeTime date={new Date('2020-01-02T01:02:03Z')} noTitle={true} />
  </Link>
</Tooltip>

Props

RelativeTime

이름 기본값 타입 설명
datetime Required string 시간을 나타내는 ISO8601 시간.
date string datetime을 넘기는 대신 date prop에 완전한 Date 객체를 넘길 수 있습니다.
format 'auto' 'auto' | 'micro' | 'elapsed' 시간을 표시할 형식.
tense 'auto' 'auto' | 'past' | 'future' 상대 시간을 표시할 때 사용할 시제.
precision 'second' 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' 경과 시간을 표시할 때 사용할 정밀도.
threshold 'P30D' string 상대 날짜를 표시할 임계값(ISO8601 기간).
prefix 'on' string 현지화된(비상대) 날짜를 표시할 때 사용할 접두사.
second 'numeric' | '2-digit' 초를 렌더링할 형식.
minute 'numeric' | '2-digit' 분을 렌더링할 형식.
hour 'numeric' | '2-digit' 시간을 렌더링할 형식.
weekday 'short' | 'long' | 'narrow' 요일을 렌더링할 형식.
day 'numeric' | '2-digit' 일을 렌더링할 형식.
month 'numeric' 'numeric' | '2-digit' | 'short' | 'long' | 'narrow' 월을 렌더링할 형식.
year 'numeric' | '2-digit' 연도를 렌더링할 형식.
timeZoneName 'long' | 'short' | 'shortOffset' | 'longOffset' | 'shortGeneric' | 'longGeneric' 시간대를 렌더링할 형식.
ref React.RefObject<RelativeTimeElement>
noTitle boolean 기본적으로 요소에 제공되는 title 속성을 제거합니다.
attributeChangedCallback (attrName: string, oldValue: unknown, newValue: unknown) => void
connectedCallback () => void
onRelativeTimeUpdated null | (event: RelativeTimeUpdatedEvent) => void
update () => void
as "relative-time" React.ElementType

더 알아보기 (Learn more)

  • RelativeTime 접근성 문서에서 스크린 리더 동작을 확인하세요.
  • RelativeTime 가이드라인에서 사용 시점을 살펴보세요.
  • relative-time-element 커스텀 엘리먼트의 동작은 해당 엘리먼트 문서를 참고하세요.