-
Notifications
You must be signed in to change notification settings - Fork 4
Function.formatTime
kodiakhq[bot] edited this page Dec 2, 2024
·
56 revisions
@sumup-oss/intl / formatTime
formatTime(
date
,locales
?,timeStyle
?):string
Formats a Date
with support for various
time styles.
Parameter | Type | Default value |
---|---|---|
date |
FormattableTime |
undefined |
locales ? |
string | string [] |
undefined |
timeStyle ? |
undefined | "short" | "long" | "full" | "medium"
|
'short' |
string
import { formatTime } from '@sumup-oss/intl';
const time = new Date(2000, 1, 1, 9, 55);
const locale = 'en-GB';
formatTime(time, locale, 'short'); // '09:55'
formatTime(time, locale, 'medium'); // '09:55:00'
formatTime(time, locale, 'long'); // '09:55:00 CET'
formatTime(time, locale, 'full'); // '09:55:00 Central European Standard Time'
In runtimes that don't support the Intl.DateTimeFormat
API, the date is
formatted using the Date.toLocale(Date|Time)String
API.
In runtimes that don't support the timeStyle
option, the styles are
approximated using fallback options.