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:
English (US)
Spanish (Spain)
French (France)
German (Germany)
Italian (Italy)
Portuguese (Brazil)
Japanese (Japan)
Chinese (China)
Arabic (Saudi Arabia)
Russian (Russia)
const { getLongTime } = require('platzidate');
console.log(getLongTime('en-US'));
Output:Wednesday, March 4, 2026 at 10:30:45 AM GMT
const { getLongTime } = require('platzidate');
console.log(getLongTime('es-ES'));
Output:miércoles, 4 de marzo de 2026, 10:30:45 GMT
const { getLongTime } = require('platzidate');
console.log(getLongTime('fr-FR'));
Output:mercredi 4 mars 2026 à 10:30:45 UTC
const { getLongTime } = require('platzidate');
console.log(getLongTime('de-DE'));
Output:Mittwoch, 4. März 2026 um 10:30:45 GMT
const { getLongTime } = require('platzidate');
console.log(getLongTime('it-IT'));
Output:mercoledì 4 marzo 2026, 10:30:45 GMT
const { getLongTime } = require('platzidate');
console.log(getLongTime('pt-BR'));
Output:quarta-feira, 4 de março de 2026 10:30:45 GMT
const { getLongTime } = require('platzidate');
console.log(getLongTime('ja-JP'));
Output:2026年3月4日水曜日 10:30:45 GMT
const { getLongTime } = require('platzidate');
console.log(getLongTime('zh-CN'));
Output:2026年3月4日星期三 GMT 10:30:45
const { getLongTime } = require('platzidate');
console.log(getLongTime('ar-SA'));
Output:الأربعاء، 4 مارس 2026 في 10:30:45 غرينتش
const { getLongTime } = require('platzidate');
console.log(getLongTime('ru-RU'));
Output:среда, 4 марта 2026 г., 10:30:45 GMT
Locale Comparison Table
| Locale | Language | Date Format Style |
|---|
en-US | English (United States) | Month Day, Year |
es-ES | Spanish (Spain) | Day de Month de Year |
fr-FR | French (France) | Day Month Year |
de-DE | German (Germany) | Day. Month Year |
it-IT | Italian (Italy) | Day Month Year |
pt-BR | Portuguese (Brazil) | Day de Month de Year |
ja-JP | Japanese (Japan) | Year年Month月Day日 |
zh-CN | Chinese (China) | Year年Month月Day日 |
ar-SA | Arabic (Saudi Arabia) | Day Month Year (RTL) |
ru-RU | Russian (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.