formatDate

February 21, 2020 ยท View on GitHub

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

TypeRequiredDefaultDescription
stringNononeShorthand date-only formatting specification. Possible values: full, long, medium, short.
formatDate(new Date(2020, 0, 1), { date: 'full' });
// Wednesday, January 1, 2020

datetime

TypeRequiredDefaultDescription
stringNononeShorthand 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

TypeRequiredDefaultDescription
stringNononeFlexible 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

TypeRequiredDefaultDescription
stringNononeShorthand 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