To create a Date Object with the current date and time, add the variable today to your js file:
If you want to get dates in the format DD-MM-YYY, you need to add the following variable:
var date = today.getDate () + '-' + (today.getMonth () + 1) + '-' + today.getFullYear ();
var date = today.getDate()+'-'+(today.getMonth()+first)+'-'+today.getFullYear();
- today.getFullYear () – Display the year with 4 digits.
- today.getMonth () + 1 – Display month.
- today.getDate () – Display the date.
If you prefer a different format, just change the order of the commands.
To display the time in HH: MM: SS format, edit your file as follows:
- today.getHours () – Display hours.
- today.getMinutes () – Display minutes.
- today.getSeconds () – Display seconds.
Combine two code segments to display the full date and time in DD-MM-YYY and HH: MM: SS format. Edit your file as follows: