javascrip new Date code example
Example 1: new date javascript
let today = new Date();
let birthday = new Date("December 17, 1995 03:24:00");
let birthday = new Date("1995-12-17T03:24:00");
let birthday = new Date(1995, 11, 17);
let birthday = new Date(1995, 11, 17, 3, 24, 0);
let birthday = new Date(628021800000);
let [month, date, year] = new Date().toLocaleDateString("en-US").split("/");
let [hour, minute, second] = new Date()
.toLocaleTimeString("en-US")
.split(/:| /);
let date = new Date(98, 1);
date.setYear(98);
date.setFullYear(98);
Example 2: new date parameters javascript
new Date(year, month, date, hours, minutes, seconds, ms)
Example 3: new date() javascript
var date = new Date();
var date = new Date(year, month, day, hours, minutes, seconds, milliseconds);
Example 4: display date in javascript
<button onclick="displayDate()">The time is?</button>
<script>
function displayDate() {
document.getElementById("demo").innerHTML = Date();
}
</script>