How to use date in javascript and the different date methods?

The Date object is a datatype built into the JavaScript language. Date objects are created with the new Date( ). Date expression with arguments

  • new Date( )
  • new Date(datestring)
  • new Date(year,month,date[,hour,minute,second,millisecond ])

Description of the parameters:

  • No Argument:With no arguments, the Date( ) constructor creates a Date object set to the current date and time.
  • Datestring: When one string argument is passed, it is a string representation of a date, in the format accepted by the Date.parse( ) method.
  •  7 agruments: To use the last form of constructor given above, Here is the description of each argument:
    • 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

Date Methods:

  •  Date()            – Returns today’s date and time
  • getDate()        -Returns the day of the month for the specified date according to local time.
  • getDay()         -Returns the day of the week for the specified date according to local time.
  • getFullYear() -Returns the year of the specified date according to local time.
  • getHours()      -Returns the hour in the specified date according to local time.
  • getMonth()     -Returns the month in the specified date according to local time.
  • getSeconds()  -Returns the seconds in the specified date according to local time.
  • getTime()        -Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC.
  • getTimezoneOffset()   -Returns the time-zone offset in minutes for the current locale.
  • getUTCDate()        -Returns the day (date) of the month in the specified date according to universal time.
  • getUTCDay()          -Returns the day of the week in the specified date according to universal time.
  • getUTCFullYear()   -Returns the year in the specified date according to universal time.
  • getUTCHours()      -Returns the hours in the specified date according to universal time.
  • getUTCMilliseconds()     -Returns the milliseconds in the specified date according to universal time.
  • getUTCMinutes()            -Returns the minutes in the specified date according to universal time.
  • getUTCMonth()  -Returns the month in the specified date according to universal time.
  • getUTCSeconds()    -Returns the seconds in the specified date according to universal time.

Leave a Reply

%d bloggers like this: