print date javascript code example
Example 1: js date methods
var d= new Date();
d.getFullYear();
d.getMonth();
d.getDate();
d.getHours();
d.getMinutes();
d.getSeconds();
d.getMilliseconds()
d.getTime();
d.getDay();
d.Date.now();
d.setDate()
d.setFullYear()
d.setHours()
d.setMilliseconds()
d.setMinutes()
d.setMonth()
d.setSeconds()
d.setTime()
Example 2: javascript current date time
var today = new Date().toLocaleDateString(undefined, {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
})
Example 3: new date() javascript
var date = new Date();
var date = new Date(year, month, day, hours, minutes, seconds, milliseconds);
Example 4: calculate today date javascript
var today = new Date();
Example 5: display date in javascript
<button onclick="displayDate()">The time is?</button>
<script>
function displayDate() {
document.getElementById("demo").innerHTML = Date();
}
</script>