The Date Object in JavaScript:

In JavaScript you have a predefine function for date. The “Date()” function is use for it. The Date () function will return the current date of your PC or Laptop in an Indian Standard Time.

Example:

How to Create Date Object:

You know that in JavaScript you already have a predefine date function but you can also crate a date object. To create a new pattern of date you have to use “new Date()” the date constructor.

First of all you have to think that what things a date should consist. So the answer is a date consist a year, a month, a week, a day, a minute, a second and a millisecond. So you can use these parameters to create a date object.

Here is four different ways for creating date:

  • new Date() : it will return the date which is a set of current date and time
  • new Date(millisecond) : numeric argument is pased in it and it will return date and time by the getTime() method
  • new Date(dateString): it will return the date which is a set of specified date and time
  • new Date(year, month, day, hrs, minutes, seconds, milliseconds): passing 7 arguments in it and it will return the date of that combination

Example:

In following example we create all pattern of Date

 

3 responses to “The Date Object in JavaScript”

  1. Tammy says:

    nice content on your site. Thanx budy

  2. Hortencia Plexico says:

    Simply wanna comment on few general things, The website style and design is perfect, the subject matter is rattling excellent : Thanks.

  3. Leopoldo Jensen says:

    woh I am lucky to find this website through google. You have very good content………

Leave a Reply

Your email address will not be published. Required fields are marked *