# General Translation Platform: formatDateTime URL: https://generaltranslation.com/en-US/docs/platform/core/reference/utility-functions/formatting/format-date-time.mdx --- title: formatDateTime description: Format dates and times without a GT instance. API reference for formatDateTime. --- [`formatDateTime`](/docs/platform/core/reference/gt-class-methods/formatting/format-date-time) is a standalone utility function from General Translation's Core library that formats dates and times according to locale-specific conventions. It returns a locale-aware string for a `Date`. ## Overview [#overview] Import `formatDateTime` directly from `generaltranslation` and call it with a `Date` and an options object. It does not require an API key or a [GT](/docs/platform/core/reference/gt-class/constructor) instance. For instance-based formatting that inherits the instance locale, use the [`formatDateTime`](/docs/platform/core/reference/gt-class-methods/formatting/format-date-time) method on a [`GT`](/docs/platform/core/reference/gt-class/constructor) instance instead. ```typescript import { formatDateTime } from 'generaltranslation'; const formatted = formatDateTime(new Date(), { locales: 'de-DE', dateStyle: 'medium', timeStyle: 'short', }); // Returns a locale-formatted string, e.g. "26.09.2025, 17:33" ``` Signature: ```typescript formatDateTime( date: Date, options?: { locales?: string | string[] } & Intl.DateTimeFormatOptions ): string ``` ## How it works [#how-it-works] - **Underlying API.** Uses the same [`Intl.DateTimeFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) as the GT class method, so all standard `Intl.DateTimeFormat` options are supported. - **Locale resolution.** When `locales` is an array, locales are tried in order. When `locales` is omitted, it falls back to the library default locale, `en`. - **Time zones.** Output respects the `timeZone` option when provided; otherwise the runtime's local time zone is used. Different locales have different default date/time formats and 12-hour vs. 24-hour preferences. - **Caching.** Results are cached internally for performance across repeated locale and options combinations. ## Parameters [#parameters] | Parameter | Description | Type | Optional | Default | | --- | --- | --- | --- | --- | | [`date`](#date) | The date object to format. | `Date` | No | — | | [`options`](#options) | Formatting configuration, including the target locale(s) and any `Intl.DateTimeFormat` options. | `{ locales?: string \| string[] } & Intl.DateTimeFormatOptions` | Yes | `{}` | ### `date` [#date] **Type** `Date` · **Required** The `Date` object to format. ### `options` [#options] **Type** `{ locales?: string | string[] } & Intl.DateTimeFormatOptions` · **Optional** · **Default** `{}` Formatting configuration. The table lists common options exposed by the published Core types and their effective Core defaults. See the [`Intl.DateTimeFormat` constructor options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options) for supplemental standard and runtime-specific details. | Property | Description | Type | Optional | Default | | --- | --- | --- | --- | --- | | `locales` | Locale(s) for formatting. Tried in order when an array is passed. | `string \| string[]` | Yes | `en` | | `localeMatcher` | Locale matching algorithm. | `'lookup' \| 'best fit'` | Yes | `'best fit'` | | `dateStyle` | Overall date formatting style. | `'full' \| 'long' \| 'medium' \| 'short'` | Yes | — | | `timeStyle` | Overall time formatting style. | `'full' \| 'long' \| 'medium' \| 'short'` | Yes | — | | `weekday` | Weekday representation. | `'long' \| 'short' \| 'narrow'` | Yes | — | | `era` | Era representation. | `'long' \| 'short' \| 'narrow'` | Yes | — | | `year` | Year representation. | `'numeric' \| '2-digit'` | Yes | `'numeric'` when no styles or components are set | | `month` | Month representation. | `'numeric' \| '2-digit' \| 'long' \| 'short' \| 'narrow'` | Yes | `'numeric'` when no styles or components are set | | `day` | Day representation. | `'numeric' \| '2-digit'` | Yes | `'numeric'` when no styles or components are set | | `dayPeriod` | Day-period width for 12-hour cycles. | `'narrow' \| 'short' \| 'long'` | Yes | — | | `hour` | Hour representation. | `'numeric' \| '2-digit'` | Yes | — | | `minute` | Minute representation. | `'numeric' \| '2-digit'` | Yes | — | | `second` | Second representation. | `'numeric' \| '2-digit'` | Yes | — | | `fractionalSecondDigits` | Number of fractional second digits. | `1 \| 2 \| 3` | Yes | — | | `timeZoneName` | Time zone name format. | `'long' \| 'short' \| 'longOffset' \| 'shortOffset' \| 'longGeneric' \| 'shortGeneric'` | Yes | — | | `timeZone` | IANA time zone name or supported UTC offset identifier. | `string` | Yes | runtime time zone | | `hour12` | Whether to use 12-hour time format. | `boolean` | Yes | locale-dependent | | `hourCycle` | Hour cycle preference. | `'h11' \| 'h12' \| 'h23' \| 'h24'` | Yes | locale-dependent | | `calendar` | Calendar system to use. | `string` | Yes | `'gregory'` | | `numberingSystem` | Numbering system for digits. | `string` | Yes | `'latn'` | | `formatMatcher` | Format matching algorithm. | `'basic' \| 'best fit'` | Yes | `'best fit'` | `dateStyle` and `timeStyle` can be combined with each other, but not with individual date-time component options such as `year`, `month`, or `hour`. `hour12` overrides `hourCycle`, and `dayPeriod` only affects 12-hour cycles. Core sets `calendar: 'gregory'` and `numberingSystem: 'latn'`; upstream `Intl.DateTimeFormat` otherwise chooses both from the locale. ## Returns [#returns] **Type** `string` The date and time formatted according to locale conventions. ## Examples [#examples] ```typescript import { formatDateTime } from 'generaltranslation'; const date = new Date('2024-03-14T14:30:45Z'); // Basic formatting with an explicit locale console.log(formatDateTime(date, { locales: 'en-US', timeZone: 'UTC' })); // Output: "3/14/2024" // German formatting console.log(formatDateTime(date, { locales: 'de-DE', timeZone: 'UTC' })); // Output: "14.3.2024" // Multiple locale fallbacks console.log(formatDateTime(date, { locales: ['ja-JP', 'en-US'], timeZone: 'UTC' })); // Output: "2024/3/14" (Japanese format) ``` ```typescript // Date and time styles const date = new Date('2024-03-14T14:30:45Z'); // Full date style console.log(formatDateTime(date, { locales: 'en-US', dateStyle: 'full', timeZone: 'UTC', })); // Output: "Thursday, March 14, 2024" // Long date with short time console.log(formatDateTime(date, { locales: 'fr-FR', dateStyle: 'long', timeStyle: 'short', timeZone: 'UTC', })); // Output: "14 mars 2024 à 14:30" ``` ```typescript // Time zone handling const date = new Date('2024-03-14T14:30:45Z'); const timeZones = ['America/New_York', 'Europe/London', 'Asia/Tokyo']; timeZones.forEach((timeZone) => { const formatted = formatDateTime(date, { locales: 'en-US', timeZone, dateStyle: 'medium', timeStyle: 'medium', }); console.log(`${timeZone}: ${formatted}`); }); // Output varies based on daylight saving time ``` ## Notes [#notes] - Uses the same underlying `Intl.DateTimeFormat` as the GT class method. - Results are cached internally for performance with repeated locale/options combinations. - All standard `Intl.DateTimeFormat` options are supported. - Time zones are handled correctly when specified. Output without a fixed `timeZone` depends on the runtime environment.