Yogesh Chauhan's Blog

How to get Current Year, Month and Date in JavaScript?

in JavaScript on August 13, 2020

Using JavaScript Date Objects we can get the current year, month and date as well as manipulate those as well. But that's not the talking point in this post.

Get Year

The getFullYear() method returns the full year of any specified date.

So, we can create a date object first and then using that date we can get the year.

var d = new Date();

// 2020

Get Month

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

So, similarly like year, we can create a date object first and then using that date we can get the month.

But, we need to add 1 to the number as we will get the month from 0 to 11.

var d = new Date();

// 8

Get Date

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

So, similarly like year and month, we can create a date object first and then using that date we can get the day.

var d = new Date();

// 14

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Dec 4 What is Etrieve Flow? #Dec 2 The unique operator($) in Envision Basic #Nov 25 Steps to Install Microsoft SQL Server on a MacOS #Nov 11 What is DevOps? #Nov 10 The * arithmetic operator in Envision Basic #Nov 10 What are Big Data Clusters in SQL Server?
You might also like these
JavaScript Data Types and Data Structures Things to RememberJavaScriptFew more :nth-child examples in CSSCSSObject destructuring in JavaScript: Unpacking fields from objects passed as function parameterJavaScriptAdd animated hamburgers menu using Hamburgers collection on GitHubCSSOverview of Drupal and how it worksDrupalHow to make a web page look good on any device?HTMLHow to apply style to the first-child using jQuery?jQueryHow to get Current Hour, Minute and Second in JavaScript?JavaScriptHow to refresh a page using PHP at regularly occurring intervals?PHPHow to make WordPress main stylesheet (style.css)?WordPressWhat are Identifiers in JavaScript?JavaScriptA short basic guide on states in ReactReact