Function: formatDate()

formatDate(date, formatter?, utc?): string

Formats a Date object according to the specified formatter string.

Parameters

date

Date

The Date object to format

formatter?

string = 'YYYY-MM-DD hh:mm:ss'

The format string. Supports YYYY (year), MM (month), DD (day), hh (hours), mm (minutes), ss (seconds)

utc?

boolean = false

Whether to use UTC time instead of local time

Returns

string

The formatted date string

Example

const date = new Date(2024, 0, 1, 12, 30, 45);
formatDate(date, 'YYYY-MM-DD hh:mm:ss'); // Returns "2024-01-01 12:30:45"
formatDate(date, 'DD/MM/YYYY', true); // Returns "01/01/2024" in UTC