dwtutorials

Online

JavaScript - The Date Object

The Date object is a datatype built into the JavaScript language. 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 millisecond fields of the object, using either local time or UTC (universal, or GMT) time.

Syntax :-

  • year-Integer value representing the year. For compatibility (in order to avoid the       Y2K problem), you should always specify the year in full; use 1998, rather than 98.
  • month - Integer value representing the month, beginning with 0 for January to 11       for December.
  • date - Integer value representing the day of the month.
  • hour - Integer value representing the hour of the day (24-hour scale).
  • minute - Integer value representing the minute segment of a time reading.
  • second - Integer value representing the second segment of a time reading.
  • millisecond - Integer value representing the millisecond segment of a time reading.
  • JavaScript-Date Methods

    Date Methods()

    Javascript Date() method returns today's date and time and does not need any object to be called.

    Syntax :-

    Example :-

    Result

    Date and Time : Wed Nov 21 2018 13:11:06 GMT+0530 (India Standard Time)

    Date getDate() Method

    Javascript date getDate() method returns the day of the month for the specified date according to local time. The value returned by getDate() is an integer between 1 and 31.

    Syntax :-

    Example :-

    Result

    getDate() : 25

    Date getFullYear() Method

    avascript date getFullYear() method returns the year of the specified date according to local time. The value returned by getFullYear() is an absolute number. For dates between the years 1000 and 9999, getFullYear() returns a four-digit number, for example, 2008.

    Syntax :-

    Example

    Result

    getFullYear() : 1995

    Date getHours() Method

    Javascript Date getHours() method returns the hour in the specified date according to local time. The value returned by getHours() is an integer between 0 and 23.

    Syntax :-

    Example

    Result

    getHours() : 23

    Date getMilliseconds() Method

    Javascript date getMilliseconds() method returns the milliseconds in the specified date according to local time. The value returned by getMilliseconds() is a number between 0 and 999.

    Syntax :-

    Example

    Result

    getMilliseconds() : 869

    Date getMinutes() Method

    Javascript date getMinutes() method returns the minutes in the specified date according to local time. The value returned by getMinutes() is an integer between 0 and 59.

    Syntax :-

    Example

    Result

    getMinutes() : 15

    Date getMonth() Method

    Javascript date getMonth() method returns the month in the specified date according to local time. The value returned by getMonth() is an integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.

    Syntax :-

    Example

    Result

    getMonth() : 11