- JavaScript Basics
- JavaScript Home
- JavaScript Syntax
- JavaScript Placements
- JavaScript Output
- JavaScript Statements
- JavaScript Keywords
- JavaScript Comments
- JavaScript Variables
- JavaScript var
- JavaScript let
- JavaScript const
- JavaScript var Vs let Vs const
- JavaScript Operators
- JavaScript Comparison/Logical
- JavaScript Data Types
- JS Conditional Statements
- JavaScript Conditional Statement
- JavaScript if Statement
- JavaScript if-else Statement
- JavaScript switch Statement
- JavaScript Loops
- JavaScript for Loop
- JavaScript while Loop
- JavaScript do-while Loop
- JavaScript Break Continue
- JavaScript Popup Boxes
- JavaScript Dialog Box
- JavaScript alert Box
- JavaScript confirm Box
- JavaScript prompt Box
- JavaScript Functions
- JavaScript Functions
- JS Function with Parameter
- JavaScript Return Statement
- JavaScript Variable Scope
- JavaScript setTimeout() Method
- JavaScript setInterval() Method
- JavaScript Events
- JavaScript Events
- JavaScript onclick Event
- JavaScript onload Event
- JavaScript Mouse Events
- JavaScript onreset Event
- JavaScript onsubmit Event
- JavaScript Objects
- JavaScript Objects
- JavaScript Number Object
- JavaScript Array Object
- JavaScript String Object
- JavaScript Boolean Object
- JavaScript Math Object
- JavaScript RegExp Object
- JavaScript Date Object
- JavaScript Browser Objects
- JavaScript Browser Objects
- JavaScript Window Object
- JavaScript Navigator Object
- JavaScript History Object
- JavaScript Screen Object
- JavaScript Location Object
- JavaScript Document Object
- JS Document Object Collection
- JS Document Object Properties
- JS Document Object Methods
- JS Document Object with Forms
- JavaScript DOM
- JavaScript DOM
- JavaScript DOM Nodes
- JavaScript DOM Levels
- JavaScript DOM Interfaces
- JavaScript Cookies
- JavaScript Cookies
- JavaScript Create/Delete Cookies
- JavaScript Advance
- JavaScript Regular Expression
- JavaScript Page Redirection
- JavaScript Form Validation
- JavaScript Validations
- JavaScript Error Handling
- JavaScript Exception Handling
- JavaScript try-catch throw finally
- JavaScript onerror Event
- JavaScript Multimedia
- JavaScript Animation
- JavaScript Image Map
- JavaScript Debugging
- JavaScript Browser Detection
- JavaScript Security
- JavaScript Misc
- JavaScript innerHTML
- JavaScript getElementById()
- JS getElementsByClassName()
- JS getElementsByName()
- JS getElementsByTagName()
- JavaScript querySelector()
- JavaScript querySelectorAll()
- JavaScript document.write()
- JavaScript console.log()
- JavaScript Programs
- JavaScript Programs
- JavaScript Test
- JavaScript Online Test
- Give Online Test
- All Test List
JavaScript Date
The Date object in JavaScript is used to display a date on a Web page.
JavaScript Date Object Properties
The following table describes the properties of Date object in JavaScript.
Property | Description |
---|---|
constructor | holds the value of the constructor function that has created the object |
prototype | adds properties and methods to the Date object |
JavaScript Date Object Methods
The following table describes the methods of the Date object in JavaScript.
getDate() | returns the day of the month (ranges from 1 to 31) |
getDay() | returns the numerical equivalence of the day of a week (ranges from 0 to 6). 0 for Monday |
getFullYear() | returns the numerical equivalence of the year (in 4 digits) |
getHours() | returns the hours (ranges from 0 to 23) |
getMilliseconds() | returns the milliseconds (ranges from 0 to 999) |
getMinutes() | returns minutes (ranges from 0 to 59) |
getMonth() | returns the numerical equivalence of month (ranges from 0 to 11) |
getSeconds() | returns the seconds (ranges from 0 to 59) |
getTime() | returns the number of milliseconds since midnight Jan 1, 1970 |
getTimezoneOffset() | returns the difference of time in minutes between GMT and the local time |
getUTCDate() | returns the day of the month (ranges from 1 to 31) as per the universal time |
getUTCDay() | returns the numerical equivalence of the day of the week (ranges from 0 to 6) as per the universal time |
getUTCFullYear() | returns the year in four digits as per the universal time |
getUTCHours() | returns the hour (ranges from 0 to 23) as per the universal time |
getUTCMilliseconds() | returns the milliseconds (ranges from 0 to 9999) as per the universal time |
getUTCMinutes() | returns the minutes (ranges from 0 to 59) as per the universal time |
getUTCMonth() | returns the numerical equivalence of month (ranges from 1 to 31) as per the universal time |
getUTCSeconds() | returns the seconds (ranges from 0 to 59) as per the universal time |
Parse() | parses a date string and returns the number of millisecond since the midnight of January 1, 1970 |
setDate() | sets the day of a month (ranges from 1 to 31) |
setFullYear() | sets the year in four digits |
setHours() | sets the hours (ranges from 0 to 23) |
setMilliseconds() | sets the milliseconds (ranges from 0 to 999) |
setMinutes() | sets the minutes (ranges from 0 to 59) |
setMonth() | sets the numerical equivalence of month (ranges from 0 to 11) |
setSeconds() | sets the seconds (ranges 0 from 59) |
setTime() | sets a date and time by adding or subtracting specified milliseconds to/from midnight January 1, 1970 |
setUTCDate() | sets the day of the month (ranges from 1 to 1) as per the universal time |
setUTCFullYear() | sets the year in four digits as per the universal time |
setUTCHours() | sets the hours (ranges from 0 to 23) as per the universal time |
setUTCMilliseconds() | sets the milliseconds (ranges from 0 to 999) |
setUTCMinutes() | sets the minutes (ranges from 0 to 59) as per the universal time |
setUTCMonth() | sets the numerical equivalence of month (ranges from 0 to 11) as per universal time |
setUTCSeconds() | sets the seconds (ranges from 0 to 59) as per the universal time |
toDateString() | converts the date into a string |
toLocalDateString() | converts the date into a string as per local conventions |
toLocalTimeString() | converts the time into a string as per local convention |
toLocalString() | converts the Date object into a string as per local convention |
toString() | converts the Date object into a string |
toTimeString() | converts time into a string |
toUTCString() | converts the Date object into a string as per the universal time |
UTC() | holds the number of millisecond since the midnight of January 1, 1970, as per the universal time |
valueOf() | returns the primitive value of the Date object |
JavaScript Date Example
Here is an example of JavaScript date. This JavaScript program will print the today's date and the current time as output:
<!DOCTYPE html> <html> <head> <title>JavaScript Date Example</title> </head> <body> <script type="text/javascript"> var today_date_var = new Date(); document.write("Today's date is: <b>" + today_date_var.getDate() + "/" + (today_date_var.getMonth()+1) + "/" + today_date_var.getFullYear() + "</b><br/>"); document.write("The time is: <b>" + today_date_var.getHours() + ":" + today_date_var.getMinutes() + ":" + today_date_var.getSeconds() + "</b><br/>"); </script> </body> </html>
Here is the output produced by the above JavaScript date example program:

Here is the live demo output produced by the above Date object example in JavaScript. You will watch today's date and current time as output.
« Previous Tutorial Next Tutorial »