Files
30-seconds-of-code/snippets/day-name.md
2023-04-28 22:29:23 +03:00

574 B

title, type, tags, cover, dateModified
title type tags cover dateModified
Day name snippet
date
interior 2020-11-01T20:50:57+02:00

Gets the name of the weekday from a Date object.

  • Use Date.prototype.toLocaleDateString() with the { weekday: 'long' } option to retrieve the weekday.
  • Use the optional second argument to get a language-specific name or omit it to use the default locale.
const dayName = (date, locale) =>
  date.toLocaleDateString(locale, { weekday: 'long' });
dayName(new Date()); // 'Saturday'
dayName(new Date('09/23/2020'), 'de-DE'); // 'Samstag'