@alessiofrittoli/date-utils
Version:
Lightweight TypeScript date utility functions library
83 lines (80 loc) • 3.42 kB
TypeScript
import { Timezone } from '../timezones/types.js';
import '../timezones/identifiers.js';
/**
* Format date.
*
* @param _date ( Optional ) The date string | milliseconds since UNIX epoch time | Date object. Default: `new Date()`.
* @param format ( Optional ) The format string or `Intl.DateTimeFormatOptions`.
* @param locales ( Optional ) The `Intl.LocalesArgument`.
* @param _timeZone ( Optional ) The Timezone name.
*
* Day
* - `d`: Day of the month, 2 digits with leading zeros
* - `j`: Day of the month without leading zeros
* - `D`: A textual representation of a day, three letters
* - `J`: A textual representation of a day, one letter
* - `l`: A full textual representation of the day of the week
* - `w`: Numeric representation of the day of the week
* - `N`: ISO 8601 numeric representation of the day of the week
* - `S`: English ordinal suffix for the day of the month, 2 characters. Works well with `j`
* - `z`: The day of the year (starting from 0)
* - `b`: The day period
*
* Week
* - `W`: ISO 8601 week number of year, weeks starting on Monday
*
* Month
* - `m`: Numeric representation of a month, with leading zeros
* - `n`: Numeric representation of a month, without leading zeros
* - `M`: A short textual representation of a month, three letters
* - `F`: A full textual representation of a month
* - `E`: A narrow textual representation of a month
* - `t`: Number of days in the given month
*
* Year
* - `L`: Whether it's a leap year - 1 if it is a leap year, 0 otherwise
* - `Y`: A full numeric representation of a year, at least 4 digits, with - for years BCE
* - `y`: A two digit representation of a year
*
* Time
* - `a`: Lowercase Ante Meridiem and Post Meridiem
* - `A`: Uppercase Ante Meridiem and Post Meridiem
* - `B`: Swatch Internet Time
* - `g`: 12-hour format of an hour without leading zeros
* - `G`: 24-hour format of an hour
* - `h`: 12-hour format of an hour with leading zeros
* - `H`: 24-hour format of an hour with leading zeros
* - `i`: Minutes with leading zeros
* - `s`: Seconds with leading zeros
* - `v`: Milliseconds
* - `u`: Microseconds
*
* Timezone
* - `e`: Current runtime Timezone identifier
* - `C`: Timezone identifier - long
* - `K`: Timezone identifier - long generic
* - `Q`: Timezone identifier - long offset
* - `q`: Same as `Q` but without colon
* - `R`: Timezone identifier - short
* - `V`: Timezone identifier - short generic
* - `o`: Timezone identifier - short offset
* - `I`: Whether or not the date is in Daylight Saving Time - 1 if it in DST, 0 otherwise
* - `O`: Difference to Greenwich time (GMT) without colon between hours and minutes
* - `P`: Difference to Greenwich time (GMT) with colon between hours and minutes
* - `p`: The same as `P`, but returns 'Z' instead of +00:00
* - `Z`: Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive
*
* Full Datetime
* - `c`: ISO 8601 date
* - `r`: » RFC 2822/» RFC 5322 formatted date
* - `U`: Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
*
* Misc
* - `T`: Time divider
*
* @returns The formatted Date string.
*/
declare const formatDate: (_date?: string | number | Date, format?: string | (Intl.DateTimeFormatOptions & {
timeZone?: Timezone;
}), locales?: Intl.LocalesArgument, _timeZone?: Timezone) => string;
export { formatDate };