Date : Object in javascript

An object that represents a date and time. Internally the time is stored as the number of milliseconds since 01 January, 1970 UTC. Use new Date() to get a Date for the current time or Date.now() to get the current time in milliseconds since 01 January, 1970 UTC.

 Date() : String

Returns a string representation of the current date and time.

Example :  console.log(Date());

 new Date() : Date

Returns a new Date object that represents the current date and time.
Example:
var d = new Date();
console.log(d);

 new Date(year : Number, month : Number, [date = 1 : Number, [hours = 0 : Number, [minutes = 0 : Number, [seconds = 0 : Number, [milliseconds = 0 : Number]]]]]) : Date

Returns a new Date object that represents the specified date and time. month 0 is January, 1 is February, etc. date is the calendar day, starting with 1 and will be at most 31.
Example:
var d = new Date(2002, 5, 24, 18, 30);
console.log(d);

 new Date(millisecondsSince1970 : Number) : Date

Returns a new Date object that is the specified number of milliseconds from 01 January, 1970 UTC.
Example:
var d = new Date(365 * 24 * 60 * 60 * 1000);
console.log(d.toUTCString());

 new Date(string : String) : Date

Parses string and returns a new Date object representing the specified date and time. See also Date.parse(string).
Example:
var d = new Date('Fri, 01 Jan 1971 00:00:00 GMT');
console.log(d.getUTCFullYear());

Instance Methods

getDate() : Number

Returns the date of this in local time. Date is the calendar day, starting with 1 and will be at most 31.
Example:
var d = new Date();
console.log(d.getDate());

 getDay() : Number

Returns the day of the week of this in local time. 0 = Sunday, 1 = Monday, 2 = Tuesday, etc.
Example:
var d = new Date();
console.log(d.getDay());
var dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
console.log(dayNames[d.getDay()]);

getFullYear() : Number

Returns the year of this in local time.
Example:
var d = new Date();
console.log(d.getFullYear());

getHours() : Number

Returns the hours of this in local time.
Example:
var d = new Date();
console.log(d.getHours());

getMilliseconds() : Number

Returns the milliseconds of this in local time.
Example:
var d = new Date();
console.log(d.getMilliseconds());

getMinutes() : Number

Returns the minutes of this in local time.
Example:
var d = new Date();
console.log(d.getMinutes());

getMonth() : Number

Returns the month of this in local time. 0 is January, 1 is February, etc.
Example:
var d = new Date();
console.log(d.getMonth());

getSeconds() : Number

Returns the seconds of this in local time.
Example:
var d = new Date();
console.log(d.getSeconds());

getTime() : Number

Returns the number of milliseconds since 01 January, 1970 for this. See also valueOf().
Example:
var d = new Date();
console.log(d.getTime());
console.log(d.valueOf());
console.log(+d);

getTimezoneOffset() : Number

Returns the number of minutes between local time and UTC time.
Example:
var d = new Date();
console.log(d.getTimezoneOffset());

getUTCDate() : Number

Returns the date of this in UTC time. Date is the calendar day, starting with 1 and will be at most 31.
Example:
var d = new Date();
console.log(d.getUTCDate());

getUTCDay() : Number

Returns the day of the week of this in UTC time. 0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday.
Example:
var d = new Date();
console.log(d.getUTCDay());
var dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
console.log(dayNames[d.getUTCDay()]);

getUTCFullYear() : Number

Returns the year of this in UTC time.
Example:
var d = new Date();
console.log(d.getUTCFullYear());

getUTCHours() : Number

Returns the hours of this in UTC time.
Example:
var d = new Date();
console.log(d.getUTCHours());

getUTCMilliseconds() : Number

Returns the milliseconds of this in UTC time.
Example:
var d = new Date();
console.log(d.getUTCMilliseconds());

getUTCMinutes() : Number

Returns the minutes of this in UTC time.
Example:
var d = new Date();
console.log(d.getUTCMinutes());

getUTCMonth() : Number

Returns the month of this in UTC time. 0 is January, 1 is February, etc.
Example:
var d = new Date();
console.log(d.getUTCMonth());

getUTCSeconds() : Number

Returns the seconds of this in UTC time.
Example:
var d = new Date();
console.log(d.getUTCSeconds());

setDate(date : Number) : Number

Sets the date of this. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setDate(1);
console.log(d);

setFullYear(year : Number, [month : Number, [date : Number]]) : Number

Sets the year (and optionally month and date) of this. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setFullYear(1980);
console.log(d);

setHours(hours : Number, [minutes : Number, [seconds : Number, [milliseconds : Number]]]) : Number

Sets the number of hours (and optionally minutes, seconds and milliseconds) of this. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setHours(0);
console.log(d);

setMilliseconds(milliseconds : Number) : Number

Sets the number of milliseconds of this. The other time components remain unchanged. Returns the time value of this.
Example:
var d = new Date();
console.log(d);
d.setMilliseconds(0);
console.log(d);

setMinutes(minutes : Number, [seconds : Number, [milliseconds : Number]]) : Number

Sets the number of minutes (and optionally seconds and milliseconds) of this. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setMinutes(0);
console.log(d);

setMonth(month : Number, [date : Number]) : Number

Sets the month (and optionally date) of this. Month 0 is January, 1 is February, etc. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setMonth(0);
console.log(d);

setSeconds(seconds : Number, [milliseconds : Number]) : Number

Sets the number of seconds (and optionally milliseconds) of this. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setSeconds(0);
console.log(d);

setTime(millisecondsSince1970 : Number) : Number

Set this date to be the specified number of milliseconds from 01 January, 1970 UTC.
Example:
var d = new Date();
d.setTime(365 * 24 * 60 * 60 * 1000);
console.log(d);

setUTCDate(date : Number) : Number

Sets the date of this. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setUTCDate(1);
console.log(d);

setUTCFullYear(year : Number, [month : Number, [date : Number]]) : Number

Sets the year (and optionally month and date) of this. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setUTCFullYear(1980);
console.log(d);

setUTCHours(hours : Number, [minutes : Number, [seconds : Number, [milliseconds : Number]]]) : Number

Sets the number of hours (and optionally minutes, seconds and milliseconds) of this. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setUTCHours(0);
console.log(d);

setUTCMilliseconds(milliseconds : Number) : Number

Sets the number of milliseconds of this. The other time components remain unchanged. Returns the time value of this.
Example:
var d = new Date();
console.log(d);
d.setUTCMilliseconds(0);
console.log(d);

setUTCMinutes(minutes : Number, [seconds : Number, [milliseconds : Number]]) : Number

Sets the number of minutes (and optionally seconds and milliseconds) of this. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setUTCMinutes(0);
console.log(d);

setUTCMonth(month : Number, [date : Number]) : Number

Sets the month (and optionally date) of this. Month 0 is January, 1 is February, etc. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setUTCMonth(0);
console.log(d);

setUTCSeconds(seconds : Number, [milliseconds : Number]) : Number

Sets the number of seconds (and optionally milliseconds) of this. The other time components remain unchanged.
Example:
var d = new Date();
console.log(d);
d.setUTCSeconds(0);
console.log(d);

toDateString() : String

Returns a string representing the date portion of this.
Example:
var d = new Date();
console.log(d.toDateString());

toISOString() : String

Returns a string representation if this in ISO 8601 format.
Example:
var d = new Date();
console.log(d.toISOString());

toJSON() : String

Returns a string representation of this suitable for storage in JSON.
Example:
var d = new Date();
console.log(d.toJSON());

toLocaleDateString() : String

Returns a human readable string of the date portion of this in local time.
Example:
var d = new Date();
console.log(d.toLocaleDateString());

toLocaleString() : String

Returns a human readable string of this in the local time.
Example:
var d = new Date();
console.log(d.toLocaleString());

toLocaleTimeString() : String

Returns a human readable string of the time potion of this in local time.
Example:
var d = new Date();
console.log(d.toLocaleTimeString());

toTimeString() : String

Returns a string representing the time portion of this.
Example:
var d = new Date();
console.log(d.toTimeString());

toUTCString() : String

Returns a human readable string of this in UTC.
Example:
var d = new Date();
console.log(d.toUTCString());

valueOf() : Number

Returns the number of milliseconds since 01 January, 1970 UTC for this. You can also obtain the value by using the date in a number context such as +date. If you need the value of the current time, use Date.now() to avoid the cost of creating a Date object. See also getTime().
Example:
var d = new Date();
console.log(d.valueOf());
console.log(d.getTime());
console.log(+d);
console.log(d / 1000 / 60 / 60 / 24 / 365 + ' years since 1970');

Date Methods
UTC(year : Number, month : Number, [date = 1 : Number, [hour = 0 : Number, [minutes = 0 : Number, [seconds = 0 : Number, [milliseconds = 0 : Number]]]]]) : Number

Returns the number of milliseconds fom 01 January, 1970 UTC of the specified date and time in UTC. month 0 is January, 1 is February, etc. date is the calendar day, starting with 1 and will be at most 31.
Example:
var d = Date.UTC(1971, 0, 1);
console.log(d);

now() : Number

Returns the number of milliseconds from 01 January, 1970 of the current time in UTC.
Example:
var now = Date.now();
console.log(now);

parse(string : String) : Number

Parses string into a date and returns the number of milliseconds this date is from 01 January, 1970 UTC. Use new Date(string) to get a Date object from a string.
Example:
var d = Date.parse('Fri, 01 Jan 1971 00:00:00 GMT');
console.log(d);

Thanks.

Comments