-1

const options = {
  year: 'numeric',
  month: 'numeric',
  day: 'numeric'
};
const dt = new Date('2023-06-16T12:00:00Z').toLocaleDateString('tr-TR', options)
console.log(dt)

The code I created is as above. It just separates date. How do I format this like 10/03/2013 Friday 12:00

Konrad
  • 21,590
  • 4
  • 28
  • 64
  • Look up the documentation for toLocaleDateString and examine the different options you can pass to it. – Quentin Feb 10 '23 at 10:15
  • Does `Friday, 10/03/2013, 12:00` works? – aca Feb 10 '23 at 10:38
  • Does this answer your question? [How do I format a date in JavaScript?](https://stackoverflow.com/questions/3552461/how-do-i-format-a-date-in-javascript) – possum Feb 10 '23 at 10:53

1 Answers1

0

TL;DR

Here's the code:

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);

Since I could only go half trough the answer, here is a link where I've found the whole one.

Firstly, I've added weekday, hour and minute inside the options, and changed the locale to en-GB (for desired slashes ( / ) DD/MM format).

So this was the result.

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

Then, as I mentioned, an user showed me how to format the date even more, like so, and we got the desired output.

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',
    })}`;
aca
  • 1,071
  • 5
  • 15