xxxxxxxxxx
// Case 1: Schedule an action at a specific time
// Set the target time for the action (HH:MM in 24-hour format)
const targetTime = '08:30';
// Get the current date and time
const currentDate = new Date();
// Create a new date by combining the current date and the target time
const actionTime = new Date(currentDate.toDateString() + ' ' + targetTime);
// Calculate the delay in milliseconds until the action time
const delay = actionTime - currentDate;
// Use setTimeout to execute the action when the delay elapses
setTimeout(() => {
// Perform the action here
console.log('Action performed!');
}, delay);
// Case 2: Delay an action for a specific time in milliseconds
// Set the delay time in milliseconds
const delay = 3000; // 3 seconds
// Use setTimeout to execute the action after the specified delay
setTimeout(() => {
// Perform the delayed action here
console.log('Delayed action performed!');
}, delay);
xxxxxxxxxx
const date = new Date(dateString).setHours(0, 0, 0); // Set hours, minutes and seconds;
xxxxxxxxxx
//new Date(year, month, day, hours, minutes, seconds, milliseconds)
new Date(1776, 6, 4, 12, 30, 0, 0);
// Timestamp method
new Date(-6106015800000);
// Date string method
new Date("January 31 1980 12:30");
xxxxxxxxxx
// Like Fri, 26 Sep 2014 18:30:00 GMT
var today = new Date();
var myToday = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0);