Back to React Spectrum

DateFormatter

packages/@internationalized/date/docs/DateFormatter.mdx

2022-12-162.1 KB
Original Source

{/* Copyright 2020 Adobe. All rights reserved. This file is licensed to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */}

import {Layout} from '@react-spectrum/docs'; export default Layout;

import docs from 'docs:@internationalized/date'; import {HeaderInfo, FunctionAPI, ClassAPI, TypeContext, InterfaceType, TypeLink, PageDescription} from '@react-spectrum/docs'; import packageData from '@internationalized/date/package.json';


category: Date and Time keywords: [date, internationalization] order: 10

DateFormatter

<PageDescription>{docs.exports.DateFormatter.description}</PageDescription>

<HeaderInfo packageData={packageData} componentNames={['DateFormatter']} sourceData={[]} />

Introduction

DateFormatter is a wrapper around the native Intl.DateTimeFormat API. It exposes the same API, but works around several browser bugs and provides polyfills for newer features. These are currently:

  • A simple polyfill for the formatRange and formatRangeToParts methods for older browsers.
  • A workaround for a bug involving the hour12 option in Chrome and and the ECMAScript spec.
  • A workaround for a bug involving the hourCycle option in Safari.

See the MDN docs for full details on how to use the API.

Interface

<ClassAPI links={docs.links} class={docs.exports.DateFormatter} />