formatDateTime
The formatDateTime function formats a JavaScript Date object into a combined date and time string, using customizable date and time formats with a specified separator.> function formatDateTime(date, {
dateFormat = "YYYY-MM-DD",
timeFormat = "hh:mmA",
seperator = " | ",
}: FormatDateAndTimeParams): string
- date (optional): A JavaScript Date object to format, defaults to current date.
- dateFormat (optional): A string specifying the date format. Defaults to `YYYY-MM-DD`.
- timeFormat` (optional): A string specifying the time format. Defaults to `hh:mmA`.
- separator (optional): A string used to separate the date and time portions. Defaults to a space ` | `.
- Returns: A string representing the formatted date and time.
Supported formats
Refer to `formatDate` for supported date formats
Refer to `formatTime` for supported time formats
Example
import { formatDateTime } from "@explita/daily-toolset";
const date = new Date();
const formattedDateTime = formatDateTime(date, {
dateFormat: "DD Month YYYY",
timeFormat: "HH:mm",
separator: " at ",
});
console.log(formattedDateTime); // e.g., "25 October 2023 at 14:30"