Home > OS >  get the day of the date in text format
get the day of the date in text format

Time:06-24

Returning a list from the backend. This list is the notifications list. I want to write the date of each element next to it. But I want to write only the day of this date as text. I want these days in abbreviated TR format.

For example;

Sal (TR) = Tue

enter image description here

const stringToDate = (stringDate) => { // stringDate: '16-05-2022'
  const dateArray = stringDate.split('-');
  return (new Date(dateArray[2], (dateArray[1] - 1).toString().padStart(2, '0'), dateArray[0].padStart(2, '0')));
};

const day = new Date(stringToDate(props.notification?.notificationList?.createdAt));
const notificationDay = day.toLocaleString('tr', { day: 'short' });
console.log(notificationDay);

CodePudding user response:

Use weekday

const notificationDay = day.toLocaleString('tr', { weekday: 'short' });
console.log(notificationDay);
  • Related