programing

DateTimeFormat 옵션을 가져오는 방법

skycolor 2023. 6. 11. 10:32
반응형

DateTimeFormat 옵션을 가져오는 방법

저장하고 싶습니다.DateTimeFormatOptions위해서date.toLocaleString()내 앱의 여러 위치에서 사용할 수 있습니다.다음과 같이 정의했습니다.

export const timeFormat = { month: 'numeric', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false, timeZoneName: 'short', time  Zone: 'UTC'}

그리고 저는 다음을 얻습니다.

Argument of type '{ month: string; day: string; hour: string; minute: string; hour12: boolean; timeZoneName: string; timeZone: string; }' is not assignable to parameter of type 'DateTimeFormatOptions'.
  Types of property 'month' are incompatible.
    Type 'string' is not assignable to type '"numeric" | "2-digit" | "short" | "long" | "narrow" | undefined'.

그러나 ImportDateTimeFormatOptions를 찾을 수 없습니다.결국 저는 날짜 형식을 지정하는 도우미 메소드를 작성했지만, 사용자가 날짜 환경설정을 변경하도록 허용할 수 있기 때문에 가져올 필요가 있을 수 있습니다.

그것은 물건 안에 있습니다.수입할 필요가 없습니다.유형을 다음으로 설정합니다.Intl.DateTimeFormatOptions.

const timeFormat: Intl.DateTimeFormatOptions = { month: 'numeric', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false, timeZoneName: 'short', timeZone: 'UTC' }

언급URL : https://stackoverflow.com/questions/71757346/how-to-import-datetimeformatoptions-in

반응형