Function date

  • Formats the given formatString with date/time information based on the given time.

    If the formatString is *t, it will use local time and return a DateTable.

    If the formatString is !*t, it will use UTC time and return a DateTable.

    Otherwise, it will format the string with the given specifiers (specifiers are based on the C function strftime)

    The following specifiers are supported:

    Specifier Meaning Example
    %a Abbreviated weekday name Wed
    %A Full weekday name * Wednesday
    %b Abbreviated month name * Sep
    %B Full month name * September
    %c Date and time * 09/16/98 23:48:10
    %d Day of the month 16
    %H Hour, using 24-hour clock 23
    %I Hour, using 12-hour clock 11
    %j Day of year 259
    %m Month 09
    %M Minute 48
    %p Either "am" or "pm" pm
    %S Second 10
    %U Week number (first Sunday as the first day of week one) 37
    %w Weekday 3
    %W Week number (first Monday as the first day of week one) 37
    %x Date * 09/16/98
    %X Time * 23:48:10
    %y Two-digit year 98
    %Y Full year 1998
    %z ISO 8601 offset from UTC in timezone (1 minute = 1, 1 hour = 100) -0400
    %Z Timezone name or abbreviation * Eastern Daylight Time
    %% The % character %
    --- --- ---

    * indicates the value can vary depending on the current locale.

    Type Parameters

    • T extends string

    Parameters

    • formatString: T

      The string to format with either specifiers given, or the type of DateTable to return.

    • Optional time: number

      The timestamp to format the formatString from. Defaults to os.time

    Returns string extends T
        ? string | Required<DateTable>
        : T extends "*t" | "!*t"
            ? Required<DateTable>
            : string