Date Utilities API reference for date manipulation and formatting functions calendar Guide

Date Utilities

The Date utilities provide functions for formatting and manipulating dates in JavaScript.

Functions

formatDate

function formatDate(date, format = 'LLL', options = {})

Formats a date according to the specified format string and options.

International Support This function uses Intl.DateTimeFormat internally, please refer to the associated docs for details on timezone and formatting usage.

Local Timezone Usage When the ‘local’ keyword is used for the timezone option, the function will use the local timezone of the environment where the code is running. This is particularly useful for displaying dates in the user’s local time without needing to detect the timezone programmatically.

Parameters

NameTypeDefaultDescription
dateDateThe date to format
formatstring’LLL’The format string (e.g., ‘YYYY-MM-DD’, ‘LT’, ‘LL’)
optionsobjectAdditional formatting options
Options
NameTypeDefaultDescription
localestring’default’The locale to use for formatting
hour12booleantrueWhether to use 12-hour time
timezonestring’UTC’The timezone to use. Use ‘local’ for the local timezone.

Returns

A formatted date string.

Example

import { formatDate } from '@semantic-ui/utils';
const date = new Date('2023-05-15T14:30:00Z');
console.log(formatDate(date)); // "May 15, 2023 2:30 PM"
console.log(formatDate(date, 'YYYY-MM-DD')); // "2023-05-15"
console.log(formatDate(date, 'LT', { timezone: 'America/New_York' })); // "10:30 AM"
console.log(formatDate(date, 'LT', { timezone: 'local' })); // Formats using the local timezone