Skip to content

formatTime Time Formatting Utility

Function List

formatTime(timestamp, fmt?) => string

Formats a timestamp or date object into a specified time string.

Parameters

Parameter NameTypeRequiredDefault ValueDescription
timestampstring | numberYes-Timestamp or date object
fmtstringNoyyyy-MM-ddTime format

Return Value

TypeDescription
stringFormatted time string

Example

typescript
import { formatTime } from '@hy-app/ui';

const day = formatTime(new Date());
const yearMonth = formatTime(1702051200000, 'yyyy-MM-dd');
const time = formatTime(1702051200000, 'HH:mm:ss');

formatTimeToString(timestamp, format?) => string

Converts a timestamp or time format string to a formatted time or "time ago" relative time description.

Parameters

Parameter NameTypeRequiredDefault ValueDescription
timestampstring | numberYes-Timestamp or time format string
formatstringNoyyyy-MM-ddTime format, pass false to show "time ago"

Return Value

TypeDescription
stringFormatted time string or "time ago" description

Example

typescript
import { formatTimeToString } from '@hy-app/ui';

const day = formatTimeToString('2020-10-10 09:00:00');
const yearMonth = formatTimeToString(1702051200000, 'yyyy-MM-dd');
const relativeTime = formatTimeToString(1702051200000, false);

padZero(value) => string

Pads a number with zeros, adding a zero to the front of numbers less than 10.

Parameters

Parameter NameTypeRequiredDefault ValueDescription
valuestring | numberYes-Number to pad zeros to

Return Value

TypeDescription
stringPadded zero string

Example

typescript
import { padZero } from '@hy-app/ui';

const num = padZero(2);
console.log(num); // 02