O'Reilly logo

JavaScript™ 1.5 by Example by Kathie Kingsley-Hughes, Adrian Kingsley-Hughes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Date Object

The Date object offers you a wealth of date-related properties and methods.

To use the Date object, the first thing you must do is to assign it a variable name (similar to how you use the Array object):

<script language="JavaScript">
<!-- Cloaking device on!
dateVar = new Date();
// Cloaking device off -->
</script>

Now that you have done this, you can start to use the Date object.

NOTE

Using new Date() with no arguments returns the current date and time to which the system is set.

NOTE

The range of dates that can be represented in a Date object is approximately 285,616 years on either side of January 1, 1970!

Using the getFullYear Method

The first thing you can try out is retrieving the full year using the getFullYear method ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required