- ES6 - Discussion
- ES6 - Useful Resources
- ES6 - Quick Guide
- ES9 - New Features
- ES8 - New Features
- ES7 - New Features
- ES6 - Browsers
- ES6 - Image Map
- ES6 - Debugging
- ES6 - Multimedia
- ES6 - Animation
- ES6 - Validations
- ES6 - Proxy API
- ES6 - Reflect API
- ES6 - Object Extensions
- ES6 - Error Handling
- ES6 - Modules
- ES6 - Promises
- ES6 - Maps And Sets
- ES6 - Classes
- ES6 - Collections
- ES6 - Iterator
- ES6 - HTML DOM
- ES6 - RegExp
- ES6 - Math
- ES6 - Date
- ES6 - Arrays
- ES6 - New String Methods
- ES6 - Symbol
- ES6 - Strings
- ES6 - Boolean
- ES6 - Number
- ES6 - Objects
- ES6 - Page Printing
- ES6 - Void Keyword
- ES6 - Dialog Boxes
- ES6 - Page Redirect
- ES6 - Cookies
- ES6 - Events
- ES6 - Functions
- ES6 - Loops
- ES6 - Decision Making
- ES6 - Operators
- ES6 - Variables
- ES6 - Syntax
- ES6 - Environment
- ES6 - Overview
- ES6 - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
ES6 - Date
The Date object is a datatype built into the JavaScript language. Date objects are created with the new Date () as shown in the following syntax.
Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and milpsecond fields of the object, using either local time or UTC (universal, or GMT) time.
The ECMAScript standard requires the Date object to be able to represent any date and time, to milpsecond precision, within 100 milpon days before or after 1/1/1970. This is a range of plus or minus 273,785 years, so JavaScript can represent date and time till the year 275755.
You can use any of the following syntax to create a Date object using Date () constructor.
new Date( ) new Date(milpseconds) new Date(datestring) new Date(year,month,date[,hour,minute,second,milpsecond ])
Note − Parameters in the brackets are always optional.
Date Properties
Here is a pst of the properties of the Date object along with their description.
Sr.No | Property & Description |
---|---|
1 |
Specifies the function that creates an object s prototype |
2 |
The prototype property allows you to add properties and methods to an object |
Date Methods
Following is a pst of different date methods along with the description.
Sr.No | Method & Description |
---|---|
1 |
Returns today s date and time |
2 |
Returns the day of the month for the specified date according to the local time |
3 |
Returns the day of the week for the specified date according to the local time |
4 |
Returns the year of the specified date according to the local time |
5 |
Returns the hour in the specified date according to the local time |
6 |
Returns the milpseconds in the specified date according to the local time |
7 |
Returns the minutes in the specified date according to the local time |
8 |
Returns the month in the specified date according to the local time |
9 |
Returns the seconds in the specified date according to the local time |
10 |
Returns the numeric value of the specified date as the number of milpseconds since January 1, 1970, 00:00:00 UTC |
11 |
Returns the time-zone offset in minutes for the current locale |
12 |
Returns the day (date) of the month in the specified date according to the universal time |
13 |
Returns the day of the week in the specified date according to the universal time |
14 |
Returns the year in the specified date according to the universal time |
15 |
Returns the hours in the specified date according to the universal time |
16 |
Returns the milpseconds in the specified date according to the universal time |
17 |
Returns the minutes in the specified date according to the universal time |
18 |
Returns the month in the specified date according to the universal time |
19 |
Returns the seconds in the specified date according to the universal time |
20 |
Sets the day of the month for a specified date according to the local time |
21 |
Sets the full year for a specified date according to the local time |
22 |
Sets the hours for a specified date according to the local time |
23 |
Sets the milpseconds for a specified date according to the local time |
24 |
Sets the minutes for a specified date according to the local time |
25 |
Sets the month for a specified date according to the local time |
26 |
Sets the seconds for a specified date according to the local time |
27 |
Sets the Date object to the time represented by a number of milpseconds since January 1, 1970, 00:00:00 UTC |
28 |
Sets the Date object to the time represented by a number of milpseconds since January 1, 1970, 00:00:00 UTC |
29 |
Sets the full year for a specified date according to the universal time |
30 |
Sets the hour for a specified date according to the universal time |
31 |
Sets the milpseconds for a specified date according to the universal time |
32 |
Sets the minutes for a specified date according to the universal time |
33 |
Sets the month for a specified date according to the universal time |
34 |
Sets the seconds for a specified date according to the universal time |
35 |
Returns the "date" portion of the Date as a human-readable string |
36 |
Returns the "date" portion of the Date as a string, using the current locale s conventions |
37 |
Converts a date to a string, using the current locale s conventions |
38 |
Returns the "time" portion of the Date as a string, using the current locale s conventions |
39 |
Returns a string representing the specified Date object |
40 |
Returns the "time" portion of the Date as a human-readable string |
41 |
Converts a date to a string, using the universal time convention |
42 |
Returns the primitive value of a Date object |