Write a Javascript Program to Display Current Date

In JavaScript, displaying the current date is quite simple.

You can use the built-in Date() object to create a new instance of the current date and then use various methods of this object to extract the required parts of the date.

Here’s an example program that displays the current date in a human-readable format:

const currentDate = new Date();
const year = currentDate.getFullYear();
const month = currentDate.getMonth() + 1;
const date = currentDate.getDate();
const formattedDate = `${year}-${month}-${date}`;
console.log(`Today's date is ${formattedDate}`);

In this program, we first create a new instance of the Date() object and store it in the currentDate variable.

We then use the getFullYear(), getMonth(), and getDate() methods of this object to extract the current year, month, and date respectively.

Note that the getMonth() method returns a zero-based index of the month, so we add 1 to it to get the actual month number.

Finally, we use template literals to format the date string in the yyyy-mm-dd format and log it to the console.

You can run this program in a browser console or in a Node.js environment to see the current date in action.

Keep in mind that the date and time used by JavaScript are based on the user’s system clock, so the displayed date may vary depending on the user’s time zone and system settings.

Overall, displaying the current date in JavaScript is a simple task that can be accomplished using the Date() object and its various methods.