js set time code example
Example 1: timeout javascript
setTimeout(function(){
//code goes here
}, 2000); //Time before execution
Example 2: javascript set timeout
setTimeout(function(){
console.log("hello");
}, 3000); //wait for atleast 3 seconds before console logging
Example 3: js set datetime
//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");
Example 4: new Date() get speicifc hours min sec
new Date().getDate() // Get the day as a number (1-31)
new Date().getDay() // Get the weekday as a number (0-6)
new Date().getFullYear() // Get the four digit year (yyyy)
new Date().getHours() // Get the hour (0-23)
new Date().getMilliseconds() // Get the milliseconds (0-999)
new Date().getMinutes() // Get the minutes (0-59)
new Date().getMonth() // Get the month (0-11)
new Date().getSeconds() // Get the seconds (0-59)
new Date().getTime() // Get the time (milliseconds since January 1, 1970)