CometChat UIKit provides flexible date/time formatting with language-aware defaults. Dates automatically adapt when you switch languages, and you can override formats globally or per-component.
Capability
Description
Language-specific defaults
Date formats auto-adapt per language (e.g., MM/DD/YYYY for en-US, DD/MM/YYYY for en-GB)
Global override
Set a custom CalendarObject that applies to all components
Per-component override
Pass a CalendarObject input to individual cometchat-date instances
When you switch languages, date formats automatically adapt:
Language
Today
Yesterday
Other Days
en-US
hh:mm A
[Yesterday]
MM/DD/YYYY
en-GB
HH:mm
[Yesterday]
DD/MM/YYYY
de
HH:mm
[Gestern]
DD.MM.YYYY
fr
HH:mm
[Hier]
DD/MM/YYYY
es
HH:mm
[Ayer]
DD/MM/YYYY
ja
HH:mm
[昨日]
YYYY/MM/DD
ko
HH:mm
[어제]
YYYY/MM/DD
zh
HH:mm
[昨天]
YYYY/MM/DD
ru
HH:mm
[Вчера]
DD.MM.YYYY
sv
HH:mm
[Igår]
YYYY-MM-DD
// Switching language automatically updates date formatsCometChatLocalize.setCurrentLanguage('ja');// Dates now show YYYY/MM/DD format with Japanese "yesterday" label
Set a custom CalendarObject that applies to all cometchat-date instances:
import { CometChatLocalize } from '@cometchat/chat-uikit-angular';// Set global date formatCometChatLocalize.setGlobalCalendarObject({ today: 'HH:mm', yesterday: '[Yesterday] HH:mm', lastWeek: 'dddd HH:mm', otherDays: 'DD/MM/YYYY'});
Once you set a custom global CalendarObject, switching languages will NOT override it. Your custom format is preserved across language changes. To revert to language-specific defaults, you would need to reset the CalendarObject.
interface CalendarObject { today?: string; // Format for today's dates yesterday?: string; // Format for yesterday's dates lastWeek?: string; // Format for dates within last 7 days otherDays?: string; // Format for all other dates relativeTime?: { minute?: string; // "1 minute ago" (use %d for number) minutes?: string; // "X minutes ago" (use %d for number) hour?: string; // "1 hour ago" (use %d for number) hours?: string; // "X hours ago" (use %d for number) };}
// Set timezone globallyCometChatLocalize.init({ language: 'en-US', timezone: 'America/Los_Angeles'});// Or check current timezoneconst tz = CometChatLocalize.getTimezone();