Function: formatDateByTimeStamp()

formatDateByTimeStamp(timeStamp, formatter?): string

Formats a date based on a given timestamp.

Parameters

timeStamp

number

The timestamp to be formatted, in milliseconds.

formatter?

string

Optional. A specific format string to format the date. Defaults to 'YYYY-MM-DD HH:mm:ss'.

Returns

string

The formatted date string.

Throws

Throws an error if the timestamp is invalid or out of range.

Example

const timestamp = new Date().getTime();
const formattedDate = formatDateByTimeStamp(timestamp);
console.log(formattedDate);