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

시간 포맷

원문 보기 위키 갱신

시간 포맷 (Format Time)

특정 로케일과 옵션에 맞춰 시간 값을 포맷하는 데 사용하는 유틸리티예요. 문자열(HH:mm[:ss]) 입력과 Date 객체 입력을 모두 지원합니다.

출처: 문서

본문

사용법 (Usage)

시간 포맷 로직은 문자열(HH:mm[:ss])과 Date 입력을 모두 지원합니다.

import { Format } from '@ark-ui/react'

예제 (Examples)

기본 (Basic)

Format.Time 컴포넌트를 사용해 기본 옵션으로 시간 값을 포맷해 보세요.

import { Format } from '@ark-ui/react/format'
import styles from 'styles/format.module.css'

export const TimeBasic = () => {
  return (
    <span className={styles.Value}>
      <Format.Time value="18:47:12" format="12h" />
    </span>
  )
}

날짜 (Date)

value로 Date 객체를 사용할 수 있어요.

import { Format } from '@ark-ui/react/format'
import styles from 'styles/format.module.css'

export const TimeWithDate = () => {
  return (
    <div className={styles.Inline}>
      <span className={styles.InlineLabel}>Boarding</span>
      <span className={styles.InlineValue}>
        <Format.Time value={new Date(2026, 1, 27, 18, 45, 34)} />
      </span>
    </div>
  )
}

초 (Seconds)

withSeconds prop을 사용하면 출력에 초를 포함시킬 수 있어요.

import { Format } from '@ark-ui/react/format'
import styles from 'styles/format.module.css'

export const TimeWithSeconds = () => {
  return (
    <div className={styles.Inline}>
      <span className={styles.InlineLabel}>Last sync</span>
      <span className={styles.InlineValue}>
        <Format.Time value="03:07:19" format="12h" withSeconds />
      </span>
    </div>
  )
}

AM/PM 라벨 (AM/PM Labels)

12시간 형식을 사용할 때 amLabel과 pmLabel을 사용해 하루 중 오전/오후 구간 라벨을 커스터마이즈할 수 있어요.

import { Format } from '@ark-ui/react/format'
import styles from 'styles/format.module.css'

export const TimeWithAmPmLabels = () => {
  return (
    <div className={styles.Inline}>
      <span className={styles.InlineLabel}>Support window</span>
      <span className={styles.InlineValue}>
        <Format.Time value="17:15:00" format="12h" amLabel="morning" pmLabel="evening" />
      </span>
    </div>
  )
}

로케일 (Locale)

로케일 프로바이더를 사용하면 특정 로케일에 맞춰 시간을 포맷할 수 있어요.

import { Format } from '@ark-ui/react/format'
import { LocaleProvider } from '@ark-ui/react/locale'
import styles from 'styles/format.module.css'

export const TimeWithLocale = () => {
  return (
    <LocaleProvider locale="ar-EG">
      <span className={styles.Value}>
        <Format.Time value="13:05" format="12h" />
      </span>
    </LocaleProvider>
  )
}

더 알아보기 (Learn more)