Skip to content

Latest commit

 

History

History
76 lines (53 loc) · 2.04 KB

formatDate.md

File metadata and controls

76 lines (53 loc) · 2.04 KB

formatDate

Formats a date based on the locale and options.

formatDate(value, options?)

Arguments

  • value - Date - Date object to be formatted
  • options? - object - Formatting options

Example

import { useGlobalize } from 'react-native-globalize';

const ExampleComponent = () => {
  const { formatDate } = useGlobalize();

  formatDate(new Date(2020, 0, 1), { skeleton: 'yMd' });
  // 1/1/2020
};

Options

Note: Specify one of date, datetime, skeleton, or time.

date

Type Required Default Description
string No none Shorthand date-only formatting specification. Possible values: full, long, medium, short.
formatDate(new Date(2020, 0, 1), { date: 'full' });
// Wednesday, January 1, 2020

datetime

Type Required Default Description
string No none Shorthand date and time formatting specification. Possible values: full, long, medium, short.
formatDate(new Date(2020, 0, 1), { datetime: 'full' });
// Wednesday, January 1, 2020 at 12:00:00 AM GMT-08:00

skeleton

Type Required Default Description
string No none Flexible formatting mechanism using a pattern with fields in canonical order. See list of skeleton patterns (not all options supported).
formatDate(new Date(2020, 0, 1), { skeleton: 'yMMMdhm' });
// Jan 1, 2020, 12:00 AM

time

Type Required Default Description
string No none Shorthand time-only formatting specification. Possible values: full, long, medium, short.
formatDate(new Date(2020, 0, 1), { time: 'full' });
// 12:00:00 AM GMT-08:00