Jacascript Date
The Date object is a built-in datatype in the JavaScript programming language. The new Date()
method is used to construct date artifacts, as shown below.
Once you've built a Date object, you can use a variety of methods to manipulate it. The year, month, day, hour, minute, second, and millisecond fields of the object can be retrieved and set using either local or UTC (universal, or GMT) time.
The Date object must be able to reflect any date and time within 100 million days before or after 1/1/1970, to millisecond precision, according to the ECMAScript standard. JavaScript will reflect date and time until the year 275755, which is a range of plus or minus 273,785 years.
Syntax
The Date() constructor can be used with any of the following syntaxes to create a Date object.
var date1 = new Date();
var date2 = new Date(milliseconds);
var date3 = new Date(datestring);
var date4 = new Date(year,month,date[hour,minute,second,millisecond ]);
Live Demo!
It's worth noting that parameters in brackets are always optional.
The following is a list of the parameters:
- The
Date()
constructor generates a Date object with the current date and time when there are no arguments. - When one numeric argument is transferred, the internal numeric representation of the date in milliseconds, as returned by the
getTime()
process, is used. Passing the argument 5000, for example, produces a date that reflects five seconds past midnight on January 1, 1970. - datestring is a string representation of a date in the format adopted by the
Date.parse()
method when one string argument is transferred. - 7 agruments agruments agruments agruments agruments To use the constructor's last form, as seen above. Here's a breakdown of each argument:
- year is an integer value that represents the current year. You should always specify the year in full, rather than 98, for compatibility (and to avoid the Y2K problem).
- month Integer value reflecting the month, ranging from 0 to 11, with 0 representing January and 11 representing December.
- date is an integer value that represents the month's day.
- hour is an integer value that represents the current day's hour (24-hour scale).
- The minute portion of a time reading is represented by an integer value.
- The second section of a time reading is represented by an integer value.
- millisecond A millisecond portion of a time reading is represented by an integer value.
Sr.No. | Property & Description |
---|---|
1 | constructor Specifies the feature that generates the prototype of an object. |
2 | prototype You can add properties and methods to an object using the prototype property. |