The Date object methods getDate(), getMonth(), and getFullYear() can be used to retrieve day, month, and full year from a date object in JavaScript.

Here is an example:

const date = new Date(2021, 8, 18);

const day = date.getDate();
const month = date.getMonth() + 1; // getMonth() returns month from 0 to 11
const year = date.getFullYear();

const str = `${day}/${month}/${year}`;

console.log(str);
// 18/9/2021

Note that the getDate(), getMonth(), and getFullYear() methods return the date and time in the local time zone of the computer where the code is running.

To get the date and time in the universal timezone (UTC), just replace the above methods with the getUTCDate(), getUTCMonth(), and getUTCFullYear() respectively:

const date = new Date(2021, 8, 18);

const day = date.getUTCDate();
const month = date.getUTCMonth() + 1; // getUTCMonth() returns month from 0 to 11
const year = date.getUTCFullYear();

const str = `${day}/${month}/${year}`;

console.log(str);
// 18/9/2021

✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.