How to get Current Year, Month and Date in JavaScript?
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

Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 3 How to embed YouTube or other video links in WordPress? Mar 3 How to change the Login Logo in WordPress? Mar 3 substring() Method in JavaScript Mar 3 Window setInterval() Method in JavaScript Mar 2 How to zoom an element on hover using CSS? Mar 2 the box-sizing property in CSS

You might also like these

How to create a Progress Bar using JavaScript?JavaScriptClean Form Input With These PHP Functions Before Inserting into DatabasePHPAvoid using new Array() in JavaScriptJavaScriptHow to use GROUPING SETS to boost GROUP BY queries in Postgres?PostgresHow to make HTML form interactive and using CSS?CSSIntroduction to components and templates Part 3: Data bindingAngulartransform-origin Property in CSSCSSExplanation of PostgreSQL PgAdmin interfacePostgresStyling Lists with CSSCSSHow to create ‘share on LinkedIn’ link using just HTML?HTMLThe Difference Between isNaN() Method And isNaN() Function In JavaScriptJavaScriptAngular 9 time clock update every minute, second, hourAngular