DateUtils API
ts
type allowDateType = Date | string | number;
parseDateOrTime()
Get time number from date or time especially "HH:mm:ss".
type:
function
tsfunction parseDateOrTime(datetime: allowDateType): number;
example
tsimport { DateUtils } from "@shihongxins/utils"; console.log(DateUtils.parseDateOrTime("00:00:06"));
nativeFormat()
Datetime format with native API.
type:
function
tsfunction nativeFormat(date?: allowDateType, format?: string): string;
example
tsimport { DateUtils } from "@shihongxins/utils"; console.log(DateUtils.nativeFormat(new Date(1678607231000), "YYYY-MM-DD"));
dayjsFormat()
The format function of dayjs.
type:
function
tsfunction dayjsFormat(date?: allowDateType, format?: string): string;
detail peer dependencies dayjs.
example
tsimport { DateUtils } from "@shihongxins/utils"; console.log(DateUtils.dayjsFormat(1678607231000, "YYYY-MM-DD"));
durationFormat()
Format the duration of time between 'from' to 'to'.
type:
function
tsfunction durationFormat(from?: allowDateType, to?: allowDateType, format?: string, pad0?: boolean): string;
example
tsimport { DateUtils } from "@shihongxins/utils"; console.log(DateUtils.durationFormat("2022-03-12", new Date(), "d days HH hours mm minutes ss seconds ago"));