JavaScript Date Methods
In this tutorial, we shall learn the JavaScript Date Methods available. Following is a quick list.
Get Methods
- getDate() returns Date as String Object.
- getDay() returns Day of the month as Number (1 to 31).
- getFullYear() returns current year in Full Year format as Number (YYYY – four digit year).
- getHours() returns number of hours passed for the day in date (0 to 24).
- getMilliseconds() returns the number of milliseconds passed in the date (0 to 999).
- getMinutes() returns the number of minutes passed in the date (0 to 59).
- getMonth() returns the number of month as Number (0 to 11).
- getSeconds() returns the number of seconds passed in the date as Number (0 to 59).
- getTime() returns the number of milliseconds passed from (00:00 01-01-1970) till the date as Number.
Set Methods
- setDate() sets the argument as the Date.
- setDay() sets the argument (1 to 31) as the day of the month in Date Object.
- setFullYear() sets the argument (YYYY- four digit) as the year in Date Object.
- setHours() sets the argument (0 ot 59) as the hours in the Date Object.
- setMilliseconds() sets the argument (0 to 999) as the number of milliseconds in the Date Object.
- setMinutes() sets the argument (0 to 59) as the number of minutes in the Date Object.
- setMonth() sets the argument (0 to 11) as the month in the Date Object.
- setSeconds() sets the argument (0 to 59) as the number of seconds in the Date Object.
- setTime() sets the argument (number of milliseconds from 00:00 01-01-1970) as the value of Date Object.
Example – Date get methods
The following example demonstrates the Date() get methods.
index.html
ADVERTISEMENT
Example – Date set methods
The following example demonstrates the Date() set methods.
index.html
Conclusion
In this JavaScript Tutorial, we learned about different methods of Date Object, with examples.