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")
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)