Sponsors

Web Designer? Design and market your own professional website with easy-to-use tools.

Compare, review and buy thousands of Laptops , software products at CheckCost.co.uk

Your Text Link Here! and your text description here!

Javascript date object tutorial

The Date object is a built-in javascript object that enables you to work with dates and times.

Create a Date object

A date object must be created before it can be used. To create a date object, it needs to be given a variable name and set to equal to the new keyword followed by Date().

<script type="text/javascript" language="javascript">

var myDate = new Date()

</script>

Display dates and times

The javascript example below will show you how to display today's date and time.

<script type="text/javascript" language="javascript">

document.write(Date());

</script>

The javascript above displays today's date and time as shown below:

The Date object will automatically hold the current date and time as its initial value.

Date object properties

Property Description
constructor Returns a reference to the Date function that created the object
prototype Allows you to add custom properties and methods of an object

Javascript Date Object Methods

Method Description
Date() Returns today's date and time
getDate() The getDate() method returns the day of the month.
getDay() The getDay() method returns a number that represents the day of the week.
Free Website Hosting

WebDevelopmentTutorials.com