Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript Date Get Methods

JS Date Get Methods

Get Date methods let us get date values (years, months, days, hours, minutes, seconds, milliseconds) from a Date Object.

Date Get Methods

The get methods listed below return Local time from existing static date objects.

Method Description
getFullYear() Get year as a four digit number (yyyy)
getMonth() Get month as a number (0-11)
getDate() Get day as a number (1-31)
getDay() Get weekday as a number (0-6)
getHours() Get hour (0-23)
getMinutes() Get minute (0-59)
getSeconds() Get second (0-59)
getMilliseconds() Get millisecond (0-999)
getTime() Get time (milliseconds since January 1, 1970)
The getFullYear() Method

The getFullYear() method returns the year of a date as a four digit number.

Old JavaScript code might use the non-standard method getYear(). getYear() is supposed to return a 2-digit year. getYear() is deprecated. Do not use it!

					 
        
          const dateTime = new Date();
          dateTime.getFullYear();
        
      
The getMonth() Method

The getMonth() method returns the month of a date as a number (0-11).

In JavaScript, January is month number 0, February is number 1. Finally, December is month number 11.

You can use an array of names to return the month as a name.

					 
        
          const dateTime = new Date();
          dateTime.getMonth();

          const months = ["January", "February", "March", "April", "May",
                       "June", "July", "August", "September", "October",
                       "November", "December"];
          let month = months[dateTime.getMonth()];
        
      
The getDate() Method

The getDate() method returns the day of a date as a number (1-31).

					 
        
          const dateTime = new Date();
          dateTime.getDate();
        
      
The getDay() Method

The getDay() method returns the weekday of a date as a number (0-6).

In JavaScript, the first day of the week (day 0) is Sunday. Some countries in the world consider the first day of the week to be Monday.

You can use an array of names, and getDay() to return weekday as a name.

					 
        
          const dateTime = new Date();
          dateTime.getDay();

          const days = ["Sunday", "Monday", "Tuesday", "Wednesday",
                      "Thursday", "Friday", "Saturday"];
          let day = days[dateTime.getDay()];
        
      
The getHours() Method

The getHours() method returns the hours of a date as a number (0-23).

					 
        
          const dateTime = new Date();
          dateTime.getHours();
        
      
The getMinutes() Method

The getMinutes() method returns the minutes of a date as a number (0-59).

					 
        
          const dateTime = new Date();
          dateTime.getMinutes();
        
      
The getSeconds() Method

The getSeconds() method returns the seconds of a date as a number (0-59).

					 
        
          const dateTime = new Date();
          dateTime.getSeconds();
        
      
The getMilliseconds() Method

The getMilliseconds() method returns the milliseconds of a date as a number (0-999).

					 
        
          const dateTime = new Date();
          dateTime.getMilliseconds();
        
      
The getTime() Method

The getTime() method returns the number of milliseconds since January 1, 1970.

					 
        
          const dateTime = new Date();
          dateTime.getTime();
        
      
The Date.now() Method

The Date.now() returns the number of milliseconds since January 1, 1970.

The Date.now() is a static method of the Date object.

You cannot use it on a date object like dateTime.now(). The syntax is always Date.now().

					 
        
          let ms = Date.now();
        
      
The getTimezoneOffset() Method

The getTimezoneOffset() method returns the difference (in minutes) between local time an UTC time

					 
        
          dateTime.getTimezoneOffset();
        
      
UTC Date Get Methods

The Coordinated Universal Time (UTC) methods listed below return universal time.

UTC time is the same as GMT (Greenwich Mean Time). The difference between Local time and UTC time can be up to 24 hours.

Method Same As Description
getUTCDate() getDate() Returns the UTC date
getUTCFullYear() getFullYear() Returns the UTC year
getUTCMonth() getMonth() Returns the UTC month
getUTCDay() getDay() Returns the UTC day
getUTCHours() getHours() Returns the UTC hour
getUTCMinutes() getMinutes() Returns the UTC minutes
getUTCSeconds() getSeconds() Returns the UTC seconds
getUTCMilliseconds() getMilliseconds() Returns the UTC milliseconds

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved