// Return today's date and timevar currentTime = new Date()
// returns the month (from 0 to 11)var month = currentTime.getMonth() + 1
// returns the day of the month (from 1 to 31)var day = currentTime.getDate()
// returns the year (four digits)var year = currentTime.getFullYear()
// write output MM/dd/yyyydocument.write(month + "/" + day + "/" + year)
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)
var now = new Date()console.log("Current Time is: " + now);
// getFullYear function will give current yearvar currentYear = now.getFullYear()console.log("Current year is: " + currentYear);
// getYear will give you the years after 1990 i.e currentYear-1990var year = now.getYear()console.log("Current year is: " + year);
// getMonth gives the month value but months starts from 0// add 1 to get actual month valuevar month = now.getMonth() + 1console.log("Current month is: " + month);
// getDate gives the date valuevar day = now.getDate()console.log("Today's day is: " + day);
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)
function generate(type,element){var value = "";var date = new Date();switch (type) {case "Date":value = date.getDate(); // Get the day as a number (1-31)break;case "Day":value = date.getDay(); // Get the weekday as a number (0-6)break;case "FullYear":value = date.getFullYear(); // Get the four digit year (yyyy)break;case "Hours":value = date.getHours(); // Get the hour (0-23)break;case "Milliseconds":value = date.getMilliseconds(); // Get the milliseconds (0-999)break;case "Minutes":value = date.getMinutes(); // Get the minutes (0-59)break;case "Month":value = date.getMonth(); // Get the month (0-11)break;case "Seconds":value = date.getSeconds(); // Get the seconds (0-59)break;case "Time":value = date.getTime(); // Get the time (milliseconds since January 1, 1970)break;}
$(element).siblings('span').text(value);}