Hackerss.com

hackerss
hackerss

Posted on

print date in specific format in Javascript

print date in specific format - Javascript:


//create a date object
const date = new Date();

//get the day of the week
const day = date.getDay();

//get the month
const month = date.getMonth();

//get the year
const year = date.getFullYear();

//get the hour
const hour = date.getHours();

//get the minutes
const minutes = date.getMinutes();

//get the seconds
const seconds = date.getSeconds();

//print the date in specific format with comments
console.log(`Today is ${day}/${month}/${year} and the time is ${hour}:${minutes}:${seconds}`);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)