Answer the question
In order to leave comments, you need to log in
How to get the day of the week and number using new Date()?
Good afternoon, I want to get tomorrow and the day after tomorrow in this format "Day of the week, day of the month". For example: "Tuesday 6 July", "Wednesday 7 July"
const date = new Date();
const tomorrow = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate() + 1}`
const dayAfterTomorrow = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate() + 2}`
const tomorrowString = tomorrow.toLocaleString('ru', { month: 'long', weekday: 'long' })
const dayAfterTomorrowString = dayAfterTomorrow.toLocaleString('ru', { month: 'long', weekday: 'long' })
Answer the question
In order to leave comments, you need to log in
const format = (date) => {
const formatted = date.toLocaleString('ru-RU', {
weekday: 'long',
day: 'numeric',
month: 'long',
});
return `${formatted[0].toUpperCase()}${formatted.slice(1)}`;
};
const today = Date.now();
const day = 24 * 60 * 60 * 1000;
const tomorrow = format(new Date(today + day));
const dayAfterTomorrow = format(new Date(today + day * 2));
console.log(tomorrow); // 'Вторник, 6 июля'
console.log(dayAfterTomorrow); // 'Среда, 7 июля'
const formatter = new Intl.DateTimeFormat('ru-RU', {
weekday: 'long',
day: 'numeric',
month: 'long',
});
const format = (date) => {
const formatted = formatter.format(date);
return `${formatted[0].toUpperCase()}${formatted.slice(1)}`;
};
const today = Date.now();
const day = 24 * 60 * 60 * 1000;
const tomorrow = format(new Date(today + day));
const dayAfterTomorrow = format(new Date(today + day * 2));
console.log(tomorrow); // 'Вторник, 6 июля'
console.log(dayAfterTomorrow); // 'Среда, 7 июля'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question