YogeshChauhan . com

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 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to uninstall Cocoapods from the Mac OS? #4 How to add Read More Read Less Button using JavaScript? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

May 5 Use inline if to make a shorter conditional syntax in React May 4 What is Conditional Rendering in React? May 3 How does @extend rule work in SCSS (Sass)? May 2 How different is Handling Events in React vs HTML DOM? May 2 How to create bouncing balls using HTML canvas and JavaScript? Apr 30 HTML canvas methods

You might also like these

12 URLSearchParams methods in JavaScriptJavaScriptINTERSECT and EXCEPT in PostgresPostgresWhat are Null Sessions?MiscThe difference between isFinite() method and isFinite() function in JavaScriptJavaScriptHow to detect if browser supports WebP format on server side PHP script?PHPHow to get current timestamp in Swift 4 and 5?SwiftIntroduction to Angular modules Part 2: NgModules and componentsAngularWhat does JSX do in React?ReactIntroduction to components and templates Part 2: Templates and viewsAngularWordPress 5.7 is migrating to latest jQuery version and people are freaking outjQuerySafe Practice to add Links to cross-origin destinationUI/UX5 Key Principles Of Good Website UsabilityUI/UX