Skip to content
Related Articles

Related Articles

Improve Article

JavaScript Date prototype Property

  • Last Updated : 30 Jun, 2020

Below is the example of Date prototype Property.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

  • Example:




    <script>
        
      var birthday = new Date('June 21, 2018 16:44:23');
      var date1 = birthday.getDate(); 
      var day1 = birthday.getDay(); 
      var year1 = birthday.getFullYear(); 
      var hour1 = birthday.getHours(); 
      var ms1 = birthday.getMilliseconds(); 
      var m1 = birthday.getMinutes(); 
      var mth1 = birthday.getMonth(); 
      var time1 = birthday.getTime(); 
      var s1 = birthday.getSeconds(); 
      var offset = birthday.getTimezoneOffset(); 
      var date2 = birthday.getUTCDate(); 
      var day2 = birthday.getUTCDay(); 
      var year2 = birthday.getUTCFullYear(); 
      var hour2 = birthday.getUTCHours(); 
      var ms2 = birthday.getUTCMilliseconds();
      var um1 = birthday.getUTCMinutes();
      var umth = birthday.getUTCMonth();
      var us = birthday.getUTCSeconds();
      
      document.write(date1 +"<br>");
      document.write(day1 +"<br>");
      document.write(year1 +"<br>");
      document.write(hour1 +"<br>");
      document.write(ms1 +"<br>");
      document.write(m1 +"<br>");
      document.write(mth1 +"<br>");
      document.write(time1 +"<br>");
      document.write(s1 +"<br>");
      document.write(offset +"<br>");
      document.write(date2 +"<br>");
      document.write(day2 +"<br>");
      document.write(year2 +"<br>");
      document.write(hour2 +"<br>");
      document.write(ms2 +"<br>");
      document.write(um1 +"<br>");
      document.write(umth +"<br>");
      document.write(us);        
    </script>
  • Output:
    21
    4
    2018
    16
    0
    44
    5
    1529579663000
    23
    -330
    21
    4
    2018
    11
    0
    14
    5
    23
    

Note: The date.prototype property represents the prototype for the Date constructor.

It has the following methods:

  • getDate():
    This method will return the day of the month for the specified date according to the local time.
  • getDay():
    This method will return the day of the week (0 for Sunday and 6 for Saturday) for the specified date according to the local time.
  • getFullYear(): It returns the year for the specified date according to local time.
  • getHours(): It returns the hour(0-23) for the specified date according to local time.
  • getMilliseconds: It returns the milliseconds (0-999) for the specified date according to local time.
  • getMinutes(): It returns the minutes (0-59) for the specified date according to local time.
  • getMonth(): It returns the month (0-11) for the specified date according to local time.
  • getSeconds(): It returns the seconds(0-59) for the specified date according to local time.
  • getTime(): It returns the number of milliseconds ellapsed since January 01, 1970 00:00:00 UTC. It is negative for time
    before the given time.
  • getTimeozneOffset(): It returns the timezone offset in minutes for current location.
  • getUTCDate(): It returns the date of the month (1-31) for the specified date according to universal time.
  • getUTCDay(): It returns the day of the week (0-6) for the specified date according to universal time.
  • getUTCFullYear(): It returns the year for the specified date according to universal time.
  • getUTCHours(): It returns the hours (0-23) for the specified date according to universal time.
  • getUTCMilliseconds(): It returns the milliseconds(0-999) for the specified date according to universal time.
  • getUTCMinutes(): It returns the minutes (0-59) for the specified date according to universal time.
  • getUTCMonth(): It returns the month (0-11) for the specified date according to universal time.
  • getUTCSeconds(): It returns the seconds (0-59) for the specified date according to universal time.

It also has some other methods which can be used to convert the date to different formats:

  • toDateString(): Returns the “date” portion of the Date as a human-readable string.
  • toGMTString(): Returns a string representing the Date based on the GMT (UT) time zone.
  • toLocaleFormat(): Converts a date to a string, using a format string.
  • toLocalestring(): Returns a string with a locality sensitive representation of this date.
  • toString(): Returns a string representing the specified Date object.
  • toTimeString(): Returns the “time” portion of the Date as a human-readable string.
  • valueOf(): Returns the primitive value of a Date object.

Supported Browsers: The browsers supported by JavaScript Date Prototype Property are listed below:

  • Google Chrome
  • Internet Explorer
  • Mozilla Firefox
  • Opera
  • Safari



My Personal Notes arrow_drop_up
Recommended Articles
Page :