Optionalunit: ManipulateTypeGet the formatted date according to the string of tokens passed in.
To escape characters, wrap them in square brackets (e.g. [MM]).
Optional settings for short formatting.
The short formatted date string.
Optionalunit: OpUnitTypeOptionalunit: OpUnitTypeOptionalunit: OpUnitTypereturns true if date is current day
Optionalunit: ManipulateTypeLocale friendly format:
de, ch = 20.10.1985
us = 10/20/1985
{includeDayOfWeek: true}
de, ch = Son, 20.10.1985
us = Sun, 10/20/1985
Converts Date in following string format: HH:mm (20:10)
Returns a localized string representing the relative time from now. Automatically handles past and future dates.
Optionaloptions: RelativeTimeOptionsOptional settings for capping and fallback behavior
Optionalcap?: numberCap the relative time at this many days. Shows "X+" format after this threshold.
Optionalfallback?: (date: AppDate) => stringCustom formatter function called when fallbackAfterDays is exceeded. Defaults to toLocalizedDateString().
OptionalfallbackAfterDays?: numberAfter this many days, use the fallback formatter instead of relative time.
A localized string like "2 days ago" or "in 3 hours"
await setAppDateLanguage('sr');
AppDate.now().subtract(2, 'day').toRelative(); // "pre 2 dana"
AppDate.now().add(3, 'hour').toRelative(); // "za 3 sata"
// With cap at 9 days
AppDate.now().subtract(15, 'day').toRelative({ cap: 9 }); // "pre 9+ dana"
// With fallback to date after 14 days
AppDate.now().subtract(20, 'day').toRelative({
cap: 9,
fallbackAfterDays: 14,
fallback: (d) => d.toLocalizedDateString()
}); // "20.12.2025"
Returns time in UTC format: HH:mm:ssZ
StaticfromCreates a AppDate instance from a date string.
A string representing a date in "YYYY-MM-DD" format.
A new AppDate instance set to the given date.
If the date string is invalid or cannot be parsed, it returns an invalid AppDate instance. The time part of the created AppDate will be set to midnight in the local timezone.
StaticfromCreates a AppDate instance from a epoch milliseconds.
A number representing a epoch milliseconds.
A new AppDate instance set to the given epoch milliseconds.
StaticfromCreates a AppDate instance from a epoch seconds.
A number representing a epoch seconds.
A new AppDate instance set to the given epoch seconds.
StaticfromCreates a AppDate instance from a local time string.
A string representing a local time in any valid (24h) time format.
A new AppDate instance set to the given time on the todays date.
If the time string is invalid, it returns an invalid AppDate instance. The date part defaults to the current date in the local timezone.
StaticfromOptionaldate: stringA string representing a UTC date in "YYYY-MM-DD" format.
A new AppDate instance set to the given UTC date.
StaticfromCreates a AppDate instance from a UTC time string.
A string representing a UTC time in "HH:mm:ssZ" format.
A new AppDate instance set to the given UTC time.
StaticinvalidCreates an invalid AppDate instance. Usiful for: Error handeling, default values, avoids null object pattern and plays nicely with validation
StaticmaxReturns the maximum supported date (2200-12-31).
A new AppDate instance set to the maximum supported date.
StaticminA new AppDate instance set to the minimum supported date (1900-01-01).
Staticnow
AppDate: A timezone-aware date and time abstraction.
IMPORTANT: Always use this wrapped abstraction instead of moment or new Date directly. You should not polute the application with randomly used date methods.
This class wraps the dayjs library to provide a consistent interface for working with dates and times in a specific timezone. It offers methods for date manipulation, comparison, and formatting, while maintaining timezone context.
Key features:
Use AppDate to ensure consistent date handling across your application, especially when dealing with different timezones or complex date logic.
Example