Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 2: Javascript Primer > A Brief Note About Dates

A BRIEF NOTE ABOUT DATES

The built-in Date object is created using the new operator and the Date() constructor function (more on prototypes and constructors later), and is used for date and time data, as you would suspect. Creating a new Date object without any parameters results in a Date object of the current date and time.

image
> var thisMoment = new Date();
> console.log(thisMoment);
Sun Jan 30 2011 21:37:19 GMT-0400 (AST)
 
> thisMoment.getFullYear();
2011

Code snippet is from date.txt

Although Date is a convenient object, and it’s certainly useful to know it’s there, I highly recommend using the open source Date.js library for doing date/time arithmetic found at www.datejs.com.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint