JavaScript Date Object
The Date object is used to work with dates and times.
Examples
Return today's date and time
How to use the Date() method to get today's date.
getTime()
Use getTime() to calculate the years since 1970.
setFullYear()
How to use setFullYear() to set a specific date.
toUTCString()
How to use toUTCString() to convert today's date (according to UTC) to a string.
getDay()
Use getDay() and an array to write a weekday, and not just a number.
Display a
clock
How to display a clock on your web page.
Complete Date Object Reference
For a complete reference of all the properties and methods that can be used with
the Date object, go to our
complete Date object reference.
The reference contains a brief description and examples of use for each
property and method!
Defining Dates
The Date object is used to work with dates and times.
We define a Date object with the new keyword. The following code line defines
a Date object called myDate:
Note: The Date object will automatically hold the current date and
time as its initial value!
Manipulate Dates
We can easily manipulate the date by
using the methods available for the Date object.
In the example below we set a Date object to a specific date (14th
January 2010):
var myDate=new Date();
myDate.setFullYear(2010,0,14);
|
And in the following example we set a Date object to be 5 days into the future:
var myDate=new Date();
myDate.setDate(myDate.getDate()+5);
|
Note: If adding five days to a date shifts the month or year, the changes are handled automatically by the
Date
object itself!
Comparing Dates
The Date object is also used to compare two dates.
The following example compares today's date with the 14th
January 2010:
var myDate=new Date();
myDate.setFullYear(2010,0,14);
var today = new Date();
if (myDate>today)
{
alert("Today is before 14th January 2010");
}
else
{
alert("Today is after 14th January 2010");
}
|
The Ektron Intranet
lets you do everything you need to do on your corporate intranet and everything you want to do... all with just one application.
What can you do with the Ektron Intranet? |

|
Navigate through content, documents, assets, colleagues and workgroups quickly and intuitively with enterprise search |

|
Communicate with friends and colleagues with forums, message boards and corporate blogging using the new Social Networking Platform |

|
Promote collaboration among coworkers in your organization through project workspaces where others can efficiently find information and work together |

|
Personalize your company profile by bookmarking and organizing favorite content, uploading assets, posting photos, blogging, and more |

|
Interact with features like tagging, flagging, wikis and ratings found in the Web 2.0 Toolbox |
 |
Author/edit content, manage navigation, menus, audit trails, workflow and approvals with the best in breed Content Management |
|
|
|
|
See why there are 20,000+ Ektron integrations worldwide. Request an
INSTANT DEMO or download a
FREE TRIAL today. |
|