Solution for Rosetta Code: Date format

Right, there are solutions to it. There is also a discussion in another thread about changing the unit test to accept either format.

The full days and months of the year cannot be retrieved from the Date object, so separate arrays have to be created from them.

Well, they actually can:

const date = new Date();

console.log(date.toLocaleDateString('en-US', { weekday: 'long' }));
// Monday (or whatever)

console.log(date.toLocaleDateString('en-US', { month: 'long' }));
// March (or whatever)

Perhaps that could be an alternate solution.

1 Like