Date & Time
Date
Javascript Date is an Object which Outputs Completed date including Time and Timezone
Example : Fri May 21 2021 18:59:20 GMT+s0530 (India Standard Time)
Syntax
Here,
todayDate will get the browser's time zone and display a date as a full text string.
Example
Let's Break The Elements of Date
new Date() contains complete Date and Time including Time Zone
It Contains In This Order : Day , Month, Date, Year, Time , Time Zone
Creating Date Objects
new Date() is used to Create a New Date.
Date Objects
Once you have declared a Date Object it will be paused to that Time(It is a Static Date String). It Will Not Move According to the Clock.
Javascript Date Types
ISO Follows "YYYY-MM-DD" Format Strictly, Other Than ISO All The Formats are Browser Dependent , If in your browser, you are using MM-DD-YYYY Format then it will take inputs in same format.
Get Date Methods
Get Date Method is used to Get the Current Date Object Date.
Example
Here, It will Output your hour of the date in 24-Hour Format
Set Date Method
Set Date Method is used to set the date of the new date object.
Functions:
Example
Here, It will First Find the Difference Between 2022 year and current year and add 1 year to the current date.
You Can Directly Compare 2 Dates by Using if...else condition.
UTC Dates(Universal Time Zone Dates)
If you are Wondering about UTC Dates, Here are some Functions Which Gives date in UTC Format.
Example