Skip to main content

Overview

PlatziDate’s getLongTime() function provides powerful internationalization support through JavaScript’s built-in Intl.DateTimeFormat API. You can display dates and times in any locale format supported by the browser.

How Locale Support Works

The getLongTime() function accepts a locale parameter and uses the following formatting options:
const options = {
    weekday: 'long',      // Full weekday name
    year: 'numeric',      // Full year (e.g., 2026)
    month: 'long',        // Full month name
    day: 'numeric',       // Day of the month
    hour: 'numeric',      // Hour
    second: 'numeric',    // Second
    timeZoneName: 'short' // Short timezone name
}
These options are passed to toLocaleString() to format the current date according to the specified locale conventions.

Default Locale

If no locale is specified, PlatziDate defaults to Spanish (Spain) (es-ES):
const { getLongTime } = require('platzidate');

// Uses default es-ES locale
console.log(getLongTime());
// Output: "miércoles, 4 de marzo de 2026, 10:30:45 GMT"

Locale Examples

Here are examples showing how dates are formatted across different locales:
const { getLongTime } = require('platzidate');

console.log(getLongTime('en-US'));
Output:
Wednesday, March 4, 2026 at 10:30:45 AM GMT

Locale Comparison Table

LocaleLanguageDate Format Style
en-USEnglish (United States)Month Day, Year
es-ESSpanish (Spain)Day de Month de Year
fr-FRFrench (France)Day Month Year
de-DEGerman (Germany)Day. Month Year
it-ITItalian (Italy)Day Month Year
pt-BRPortuguese (Brazil)Day de Month de Year
ja-JPJapanese (Japan)Year年Month月Day日
zh-CNChinese (China)Year年Month月Day日
ar-SAArabic (Saudi Arabia)Day Month Year (RTL)
ru-RURussian (Russia)Day Month Year г.
The actual output may vary slightly depending on your system’s timezone and the exact time the function is called.

Finding More Locales

PlatziDate supports any valid BCP 47 language tag. For a complete list of supported locales and their formats, refer to:
Test your locale codes in a browser console using new Date().toLocaleString('your-locale') to see how dates will be formatted before implementing them in your application.

Dynamic Locale Selection

You can dynamically select locales based on user preferences:
const { getLongTime } = require('platzidate');

function getLocalizedTime(userLocale) {
    // Fallback to en-US if user locale is not provided
    const locale = userLocale || 'en-US';
    return getLongTime(locale);
}

// From user settings or browser
const userLanguage = navigator.language; // e.g., 'fr-FR'
console.log(getLocalizedTime(userLanguage));
Always provide a fallback locale to ensure your application displays dates correctly even when the user’s locale preference is unavailable.

Build docs developers (and LLMs) love