Javascript Date Objects - Properties and Methods
Description
JavaScript date object is used to create dates and times.
These are the ways to create a date object in JavaScript :
i) new Date().
[for example today = new Date() ].
ii) new Date(milliseconds).
[for example inauguration_day = new Date("August 15, 1997 10:05:00") ].
iii) new Date(dateString).
[for example inauguration_day = new Date(97,8,15) ].
new Date(year, month, day, hours, minutes, seconds, milliseconds).
[for example inauguration_day = new Date(97,8,15,10,05,0) ].
Javascript Date Objects Property
Name | Description | Version |
---|---|---|
constructor | specifies the function that creates an object's prototype. | Implemented in JavaScript 1.0 |
prototype | Use to add new properties to a date object. | Implemented in JavaScript 1.0 |
Javascript Date Objects Methods
Name | Description | Version |
---|---|---|
getDate | Use to get the day of the month of a given date according to local time. | Implemented in JavaScript 1.0 |
getDay | Use to get the day of the week of a given date according to local time. | Implemented in JavaScript 1.0 |
getFullYear | Use to get the year of a given date according to local time. | Implemented in JavaScript 1.0 |
getHours | Use to get the hour of a given date according to local time. | Implemented in JavaScript 1.0 |
getMilliseconds | Use to get the milliseconds from the current time according to local time. | Implemented in JavaScript 1.0 |
getMinutes | Use to get the minutes from the current time according to local time. | Implemented in JavaScript 1.0 |
getMonth | Use to get the month of a given date according to local time | Implemented in JavaScript 1.0 |
getSeconds | Use to get the seconds from the current time according to local time. | Implemented in JavaScript 1.0 |
getTime | Use to get the milliseconds of a given date according to local time. | Implemented in JavaScript 1.0 |
getTimezoneOffset | Use to get the difference between local time and Greenwich Mean Time (GMT). | Implemented in JavaScript 1.0 |
getUTCDate | Returns the day (date) of the month of a given date according to Coordinated Universal Time (UTC). | Implemented in JavaScript 1.0 |
getUTCDay | Returns the day of the week in the specified date according to universal time(UTC). | Implemented in JavaScript 1.0 |
getUTCFullYear | Returns the year of a given date according to universal time(UTC). | Implemented in JavaScript 1.0 |
getUTCHours | Returns the hours of given date according to universal time(UTC). | Implemented in JavaScript 1.0 |
getUTCMilliseconds | Use to get the milliseconds from a given date according to universal time (UTC). | Implemented in JavaScript 1.0 |
getUTCMinutes | Use to get the minutes from a given date according to universal time (UTC). | Implemented in JavaScript 1.0 |
getUTCMonth | Returns the months of given date according to universal time. | Implemented in JavaScript 1.0 |
getUTCSeconds | Returns the seconds of a given date according to universal time. | Implemented in JavaScript 1.0 |
getYear | Use to get the year of a given date according to local time. | Implemented in JavaScript 1.0 |
parse | Takes a date string (such as "Jan 21, 1987") and returns the number of milliseconds since January 1, 1970, 00:00:00, local time. | Implemented in JavaScript 1.0 |
setDate | Use to set the day of the month for a given date according to local time. | Implemented in JavaScript 1.0 |
setFullYear | Use to set the full year for a given date according to local time. | Implemented in JavaScript 1.0 |
setHours | Use to set the hours for a given date according to local time. | |
setMilliseconds | Use to set the milliseconds for a given date according to local time. | Implemented in JavaScript 1.0 |
setMinutes | Use to set the minutes for a given date according to local time. | Implemented in JavaScript 1.0 |
setMonth | Use to set the month for a given date according to local time. | Implemented in JavaScript 1.0 |
setSeconds | Use to set the seconds for a given date according to local time. | Implemented in JavaScript 1.0 |
setTime | Use to set the value of a Date object according to local time. | Implemented in JavaScript 1.0 |
setUTCDate | Use to set the numeric day of the month according to Coordinated Universal Time (UTC). | Implemented in JavaScript 1.0 |
setUTCFullYear | Use to set the full year for a given date according to Coordinated Universal Time (UTC). | Implemented in JavaScript 1.0 |
setUTCHours | Use to set the hour for a specified date according to Coordinated Universal Time (UTC). | Implemented in JavaScript 1.0 |
setUTCMilliseconds | Use to set the milliseconds for a specified date according to Coordinated Universal Time (UTC). | Implemented in JavaScript 1.0 |
setUTCMinutes | Use to set the minutes for a specified date according to Universal Coordinated Time (UTC). | Implemented in JavaScript 1.0 |
setUTCMonth | Use to set the month for a given date according to local time. | Implemented in JavaScript 1.0 |
setUTCSeconds | Use to set the seconds for a given date according to universal time. | Implemented in JavaScript 1.0 |
setYear | Use to set the year for a given date according to local time. | Implemented in JavaScript 1.0 |
toLocaleString | Use to convert a date to a string, using the current locale time. | Implemented in JavaScript 1.0 |
toSource | Returns a string which represents the source code of the date object. | Implemented in JavaScript 1.0 |
toString | Use to convert a date to a string. | Implemented in JavaScript 1.0 |
toUTCString | Use to convert a date to a string, using the universal time convention. | Implemented in JavaScript 1.0 |
UTC | Returns the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time. | Implemented in JavaScript 1.0 |
valueOf | Use to get the primitive value of date object. | Implemented in JavaScript 1.0 |
See also:
JavaScript Core objects, methods, properties.
Previous: JavaScript valueOf() Method: Array Object
Next:
JavaScript constructor Property: Date Object
Test your Programming skills with w3resource's quiz.
JavaScript: Tips of the Day
Add padding to the beginning of a string
const name = 'Minta Lofton'; console.log(name.padStart(13)); console.log(name.padStart(2));
With the padStart method, we can add padding to the beginning of a string. The value passed to this method is the total length of the string together with the padding. The string "Minta Lofton" has a length of 12. name.padStart(13) inserts 1 space at the start of the string, because 12 + 1 is 13.
If the argument passed to the padStart method is smaller than the length of the array, no padding will be added.
Ref: https://bit.ly/3jFRBje
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook