Creating Date Objects
Creating Date Objects
1. new Date()
2. new Date(year, month, day, hours, minutes, seconds,
milliseconds)
You cannot omit month. If you supply only one parameter it will be treated
as milliseconds.
January = 0.
December = 11.
Specifying a month higher than 11, will not result in an error but add the
overflow to the next year:
Example :-
const d = new Date(2018, 15, 24, 10, 33, 30);
Specifying:
1) getTime()
2) getMonth()
The getMonth() method returns the month of a date as a number (0-
11):
3) getDate()
The getDate() method returns the day of a date as a number (1-31):
4) getHours()
The getHours() method returns the hours of a date as a number (0-
23):
5) setDate()
6) setHours()
The setHours() method sets the hours of a date object (0-23):
7) setMinuites()
Example :-
<!DOCTYPE html>
<html>
<body>
Set date :-
<script>
const d = new Date();
d.setDate(15);
document.write(d);
</script>
</body>
</html>