Table of Contents
Back Button
Back to Chapter
Control Statements
No items found.
Function & Events
No items found.
Array and its Types
No items found.
OOP : Object Oriented Programming
No items found.
Javascript Standards
No items found.
HTML DOM
No items found.
Javascript : Advanced 1
No items found.
Javascript : Advanced 2
No items found.
Additional JavaScript
No items found.

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

var todayDate = new Date();

Here,

todayDate will get the browser's time zone and display a date as a full text string.

Example

var todayDate = new Date(); console.log(todayDate); // Output // Fri May 21 2021 18:59:20 GMT+s0530 (India Standard Time)

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

var dt = new Date(); console.log(dt.getHours()); // Output // 19

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

var dt = new Date(); dt.setFullYear(2022); console.log(dt) // Output // Sat May 21 2022 19:58:25 GMT+0530 (India Standard Time)

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

var dt = new Date(); console.log(dt.getUTCMonth()); // Output // 4
Ask queries
Contact Us on Whatsapp
Hi, How Can We Help You?