Function formatDate

  • Return the formatted date string in the given format.

    Usage:

    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
    

    Parameters

    • Optional dateIns: string | number | Date

      Original Date

    • format: string = "yyyy-MM-dd"

      Format String

    Returns string

    Return the formatted date string.