xxxxxxxxxx
// Get current date and time
var currentDateTime = new Date();
// Get the current time in hours, minutes, and seconds
var hours = currentDateTime.getHours();
var minutes = currentDateTime.getMinutes();
var seconds = currentDateTime.getSeconds();
// Display the current time
console.log("Current time: " + hours + ":" + minutes + ":" + seconds);
xxxxxxxxxx
// Create a new date object
const date = new Date();
// Get the current time
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
// Format the time as a string
const time = `${hours}:${minutes}:${seconds}`;
// Display the time
console.log(time);
xxxxxxxxxx
var start = new Date();
//do some think that takes a while here
var runTime = new Date() - start;
console.log("Script took:"+runTime+" Milliseconds to run");
xxxxxxxxxx
const t0 = performance.now();
doSomething();
const t1 = performance.now();
console.log(`Call to doSomething took ${t1 - t0} milliseconds.`);
xxxxxxxxxx
// Creating a new Date object to represent the current date and time
const currentTime = new Date();
// Getting the current time in milliseconds
const currentTimeMilliseconds = currentTime.getTime();
// Getting various components of the current time
const currentYear = currentTime.getFullYear();
const currentMonth = currentTime.getMonth() + 1; // Months are zero-based, so adding 1
const currentDate = currentTime.getDate();
const currentHour = currentTime.getHours();
const currentMinute = currentTime.getMinutes();
const currentSecond = currentTime.getSeconds();
// Formatting the current time in a desired format
const formattedTime = `${currentHour}:${currentMinute}:${currentSecond}`;
// Outputting the results
console.log("Current Time:", currentTime);
console.log("Current Time in Milliseconds:", currentTimeMilliseconds);
console.log("Current Year:", currentYear);
console.log("Current Month:", currentMonth);
console.log("Current Date:", currentDate);
console.log("Current Hour:", currentHour);
console.log("Current Minute:", currentMinute);
console.log("Current Second:", currentSecond);
console.log("Formatted Time:", formattedTime);
xxxxxxxxxx
var startTime = performance.now()
doSomething() // <---- measured code goes between startTime and endTime
var endTime = performance.now()
console.log(`Call to doSomething took ${endTime - startTime} milliseconds`)