LILLY ROBOT |
The date object displays the current date and time. A Date object is created
using the keyword new.
dateObjectname= new Date();
Displays
The Date() object has several methods.
The toLocalString() method converts the object into string.
Displays
The getDate() method returns the day of the month according to the local time. The return value starts from 1 to 31.
Displays
The getDay() method returns the day of the week according to the local time. The return value starts from 0 to 6.
Displays
The getDay() method returns the year according to the local time.
Displays
In the table below you can see some more of the date methods according to the local time.
To help you understand the table we have declared a new date object called d.
Methods | Explanation | Example |
---|---|---|
getHours() | returns the hour - values 0-23 | d.getHours() |
getMinutes() | returns the minutes - values:0-59 | d.getMinutes() |
getSeconds() | returns the seconds - values:0-59 | d.getSeconds() |
getMilliseconds() | returns the milliseconds - values:0-999 | d.getMilliseconds() |
getMonth() | returns the month - values:0-11. | d.getMonth() |
getTime() | returns the number of milliseconds since 1/1/1970 for the date object | d.getTime() |
setDate() | sets the day of the month - values:1-31 | d.setDate(2) |
setFullYear() | sets the full year | d.setFullYear(2021) |
setHours() | sets the hour - values:0-23 | d.setHours(5) |
setMinutes() | sets the minutes - values:0-59 | d.setMinutes(30) |
setSeconds() | sets the seconds - values:0-59 | d.setSeconds(3) |
setMilliseconds() | sets the milliseconds - values:0-999 | d.setMilliseconds(100) |
setMonth() | returns the month - values: 0-11 | d.setMonth(6) |
setTime() | sets the number of milliseconds since 1/1/1970 | d.setTime() |
The table below shows more of the date methods according to the Coordinated Universal Time.
Methods | Explanation | Example |
---|---|---|
getUTCDate() | returns the day of the month - values:1-31 | d.getUTCDate() |
getUTCDay() | returns the day of the week - values:0-6 | d.getUTCDate() |
getUTCMonth() | returns the month - values:0-11 | d.getUTCMonth() |
getUTCFullYear() | returns the full year | d.getUTCFullYear() |
getUTCHours() | returns the hour - values 0-23 | d.getUTCHours() |
getUTCMinutes() | returns the minutes - values:0-59 | d.getUTCMinutes() |
getUTCSeconds() | returns the seconds - values:0-59 | d.getUTCSeconds() |
getUTCMilliseconds() | returns the milliseconds - values:0-999 | d.getUTCMilliseconds() |
setUTCDate() | sets the day of the month - values:1-31 | d.setUTCDate(2) |
setUTCMonth() | returns the month - values starts from 0-11. | d.setUTCMonth(6) |
setUTCFullYear() | sets the full year | d.setUTCFullYear(2021) |
setUTCHours() | sets the hour - values 0-23 | d.setUTCHours(5) |
setUTCMinutes() | sets the minutes - values:0-59 | d.setUTCMinutes(30) |
setUTCSeconds() | sets the seconds - values:0-59 | d.setUTCSeconds(3) |
setUTCMilliseconds() | sets the milliseconds - values:0-999 | d.setUTCMilliseconds(100) |
Displays
Displays
Displays
Displays