JavaScript Tutorial

Print Current Time

You can display the current date and time in JavaScript in a couple of simple ways. One common method is by using the new Date() function. Here, new is a keyword used to create an instance of the Date object, which is responsible for handling date and time. When you use new Date() alone, it returns the current date and time in ISO format, like:

"2025-04-24T09:32:45.123Z"

However, if you want the output to be more human-readable, you can use:

new Date().toString()

This will return something like:

"Thu Apr 24 2025 19:08:57 GMT+0530 (India Standard Time)"


Another way to work with date and time is by using specific methods of the Date object. These include:

  • getDate() – Gets the day of the month
  • getMonth() – Gets the month (0–11, where January is 0)
  • getFullYear() – Gets the four-digit year
  • getHours(), getMinutes(), getSeconds() – Get time components

You can combine these methods to create a custom format like this:

const date = new Date();
const formatted = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
console.log(formatted);

This would print something like:

24/4/2025 19:8:57

console.log(new Date());