JavaScript: Dates - displaying and working with dates and time
This page introduces Date as an object that can be manipulated with JavaScript.
JavaScript code snippets listed by task and organised in a tutorial style each building on the previous example. New topics are introduced when required.
1. |
Working with the JavaScript Date object (Time included). Create a Date object using the 'var' statement and 'new' keyword with the Date() constructor function. Examples of calling Date object methods with dot notation and assigning values to variables. Write values to page. |
2. |
Working with the JavaScript Date object. Examples of calling Date object methods with dot notation and assigning values to variables. Adjust values (month) and write to the page in a recognised format (Time included). |
3. |
Calling the Date object methods directly without assigning individually to variables. Use of 'with statement' to eliminate the need to name an object each time when applying the method. Adjust values (month) and write to the page in a recognised format. |
4. |
Working with the JavaScript Date object arrays. Assigning day and month names using multiple 'if statements'. Writing formatted date to the page. |
|
See the Date object reference for list of essential methods and constructors. |
|
5. |
Working with the JavaScript Date object arrays. Assigning day and month names using user defined arrays. Writing formatted date to the page. |
6. |
Building messages with the JavaScript Date methods. Customised message depending on the day of the week. |
7. |
Building messages with the JavaScript Date methods. Customised message depending on the time of day. |
8. |
Performing addition on the Date object. Taking a pre-set date and adding a number of days to create a date set in the future. |
9. |
Build on the above and learn about JavaScript and Cookies. View code examples on JavaScript: Cookies page. |
| Suggest a code snippet to add to this category. | |
Back to top.
Copyright © 2006-2012 justfigures.co.uk

