Date is used to store date related types. There are a lot of date functions to operate with date variables. Date holds year,month,day,hour,minute,second and millisecond.
var d=new Date();
- We have created new d variable with date type.
2016-10-27T03:41:55.155Z
- This is the value holded d
Get Day of Week
The day number of the week can be get with getDay()
d.getDay()
- getDay() will return the number of the day of week. For example if it is monday it will return 1
Get Hour
We can get hour but not minute with getHours()
d.getHours()
- getHours() will return 6 if the time is 6:45
Get Minute
We can get minute with getMinutes()
d.getMinutes()
- getMinutes() will return 45 if the time is 6:45
Get Second
We can get second with getSeconds()
d.getSeconds()
- getSeconds() will return 55 if the time is 6:45:55
Get Year
We can get year with getYear()
d.getYear()
- getYear() will return 2016
Get Second
We can get second with getSeconds()
d.getSeconds()
- getSeconds() will return 55 if the hour is 6:45:55