How to convert date time to (DD/MM/YYYY)

So I’m creating a bot using noblox.js and when I get the playerInfo.joinDate it gives me this:image

But I want it like this: (DD/MM/YYYY)
How can I do that?

1 Like

What you have logged there is a Date object, which has several methods and properties you can use to format the date to your needs.

If you want a dead-simple approach you can use something like MomentJS to easily format the date, for example with the code:

If you want to do it yourself, you can. For example with the following code:

const formatMonth = month => month < 10 ? `0${month}` : month.toString();
const formatDay = day => day < 10 ? `0${day}` : day.toString();

const date = new Date();
const formattedDate = `${formatDay(date.getUTCDay())}/${formatMonth(date.getUTCMonth())}/${date.getUTCFullYear()}`;
console.log(formattedDate); // --> 03/02/2021

1 Like

Good answer :slight_smile:
For what it’s worth tho, MomentJS is definitely overkill for this! From Moment.js | Docs

In most cases, you should not choose Moment for new projects.

1 Like

I used this: