DEV Community

SARTHAK KASHMIRA
SARTHAK KASHMIRA

Posted on

Date in JS(Fully Covered)

Date object

To create a date we can use Date() and we can pass arguments in the form of strings as well.

const date=new Date() // creates a new date with present date and current time
const date1=new Date("2021-01-23") // creates date with this date 
const date2=new Date("December 02, 2021 23:45:00")
Enter fullscreen mode Exit fullscreen mode

To access the dates from Date object

We can use functions like getFullYear(),getMonth(),getDate(),getHours(),getMinutes(),getSeconds(),getMilliSeconds()

To set the dates from Date object

setFullYear(),setMonth(),setDate(),setHours(),setMinutes(),setSeconds(),setMilliSeconds()

Note that in all the above functions we should pass arguments as number.
But the getMonth() and setMonth() takes values as the month number in the form of 0-based indexing

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay