Return the formatted date string in the given format.
Supported format tokens:
yyyy
2022
MM
01
12
dd
31
HH
00
23
hh
mm
59
ss
a
AM
PM
The function creates a native Date and reads its local date and time fields. Timestamp output can therefore differ between runtime time zones.
Date
Usage:
import { formatDate } from "mazey";const ret1 = formatDate();const ret2 = formatDate("Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)", "yyyy-MM-dd hh:mm:ss a");const ret3 = formatDate(1641881235000, "yyyy-MM-dd hh:mm:ss a");const ret4 = formatDate(new Date(2014, 1, 11), "MM/dd/yyyy");console.log("Default formatDate value:", ret1);console.log("String formatDate value:", ret2);console.log("Number formatDate value:", ret3);console.log("Date formatDate value:", ret4); Copy
import { formatDate } from "mazey";const ret1 = formatDate();const ret2 = formatDate("Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)", "yyyy-MM-dd hh:mm:ss a");const ret3 = formatDate(1641881235000, "yyyy-MM-dd hh:mm:ss a");const ret4 = formatDate(new Date(2014, 1, 11), "MM/dd/yyyy");console.log("Default formatDate value:", ret1);console.log("String formatDate value:", ret2);console.log("Number formatDate value:", ret3);console.log("Date formatDate value:", ret4);
Output:
Default formatDate value: 2023-01-11 String formatDate value: 2022-01-11 02:12:26 PM Number formatDate value: 2022-01-11 02:07:15 PM Date formatDate value: 02/11/2014 Copy
Default formatDate value: 2023-01-11 String formatDate value: 2022-01-11 02:12:26 PM Number formatDate value: 2022-01-11 02:07:15 PM Date formatDate value: 02/11/2014
Optional
Original date value. Defaults to the current date and time.
Format string composed of supported format tokens. Defaults to yyyy-MM-dd.
yyyy-MM-dd
The formatted date string.
If dateIns is not a valid date.
dateIns
Return the formatted date string in the given format.
Supported format tokens:
yyyy2022MM01–12dd01–31HH00–23hh01–12mm00–59ss00–59aAMorPMThe function creates a native
Dateand reads its local date and time fields. Timestamp output can therefore differ between runtime time zones.Usage:
Output: