local string method 1

local string method

console.log(date.toLocaleString('en-US', {
    weekday: 'short', // long, short, narrow
    day: 'numeric', // numeric, 2-digit
    year: 'numeric', // numeric, 2-digit
    month: 'long', // numeric, 2-digit, long, short, narrow
    hour: 'numeric', // numeric, 2-digit
    minute: 'numeric', // numeric, 2-digit
    second: 'numeric', // numeric, 2-digit
 // Output: Tue, July 21, 2020, 10:01:14 AM

Here is what the above code is Doing:
1. We create a new Date object and pass in a date string.
2. We call the toLocaleString() method on the date object and pass in a locale string and an options object.
3. The locale string is ‘en-US’ and the options object specifies the format of the date string.
4. The toLocaleString() method returns a formatted date string.

Similar Posts