xxxxxxxxxx
const t0 = performance.now();
doSomething();
const t1 = performance.now();
console.log(`Call to doSomething took ${t1 - t0} milliseconds.`);
xxxxxxxxxx
// ⚠️ Edit :
// ⚠️ CHECK Intl : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl
//Do you need the current time ? ⌚
let date = new Date();
let time = ((date.getHours().toString()).length>1? date.getHours() : "0"+date.getHours()) +":"+ ((date.getMinutes().toString()).length>1? date.getMinutes() : "0"+date.getMinutes());
//If 4h-2min => 04:02
//If 20h-15min => 20:15
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`)
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);