0

I've formatted my date like below, but I would like the weekday to go after the DD/MM/YYYY. Is this possible?

Current output: Friday, 16/06/2023, 12:00

Desired output: 16/06/2023, Friday, 12:00

const options = {
  weekday: 'long',
  year: 'numeric',
  month: 'numeric',
  day: 'numeric',     
  hour: 'numeric',
  minute: 'numeric',
};
const dt = new Date('2023-06-16T12:00:00Z').toLocaleDateString('en-GB', options)
console.log(dt)
aca
  • 1,071
  • 5
  • 15

1 Answers1

1

You can do by custom code format of required output.

In your case to acheive desired result this code help you.

const options = {
  year: 'numeric',
  month: 'numeric',
  day: 'numeric',
  weekday: 'long',
  hour: 'numeric',
  minute: 'numeric',
};
const dt = new Date('2023-06-16T12:00:00Z');
const formattedDate = `${dt.toLocaleDateString('en-GB', {
  year: 'numeric',
  month: 'numeric',
  day: 'numeric',
})}, ${dt.toLocaleDateString('en-GB', {
  weekday: 'long',
})}, ${dt.toLocaleTimeString('en-GB', {
  hour: 'numeric',
  minute: 'numeric',
})}`;
console.log(formattedDate);
NIKUNJ PATEL
  • 2,034
  • 1
  • 7
  • 22
  • If this will help you to find a solution to your question then add it as the right answer for other people to find the right solution in the future. – NIKUNJ PATEL Feb 10 '23 at 10:56
  • I will, don't worry. The rules are that I have to wait for couple of more minutes so I can accept your answer. You'll get your +15 :) – aca Feb 10 '23 at 10:57