JavaScript DHTML/Development/Date

Материал из Web эксперт
Перейти к: навигация, поиск

A Dynamic Welcome Message

   <source lang="html4strict">

/* JavaScript Bible, Fourth Edition by Danny Goodman John Wiley & Sons CopyRight 2001

  • /

<HTML> <HEAD> <TITLE>Date String Maker</TITLE> <SCRIPT LANGUAGE="JavaScript"> function MakeArray(n) {

   this.length = n
   return this

} monthNames = new MakeArray(12) monthNames[1] = "January" monthNames[2] = "February" monthNames[3] = "March" monthNames[4] = "April" monthNames[5] = "May" monthNames[6] = "June" monthNames[7] = "July" monthNames[8] = "August" monthNames[9] = "September" monthNames[10] = "October" monthNames[11] = "November" monthNames[12] = "December" dayNames = new MakeArray(7) dayNames[1] = "Sunday" dayNames[2] = "Monday" dayNames[3] = "Tuesday" dayNames[4] = "Wednesday" dayNames[5] = "Thursday" dayNames[6] = "Friday" dayNames[7] = "Saturday" function customDateString(oneDate) {

   var theDay = dayNames[oneDate.getDay() + 1]
   var theMonth = monthNames[oneDate.getMonth() + 1]
   var theYear = oneDate.getYear()
   theYear += (theYear < 100) ? 1900 : 0
   return theDay + ", " + theMonth + " " + oneDate.getDate() + ", " + theYear

} function dayPart(oneDate) {

   var theHour = oneDate.getHours()
   if (theHour <6 )
       return "wee hours"
   if (theHour < 12)
       return "morning"
   if (theHour < 18)
       return "afternoon"
   return "evening"

} </SCRIPT> </HEAD> <BODY>

Welcome!

<SCRIPT LANGUAGE="JavaScript"> today = new Date() var header = (customDateString(today)).italics() header += "
We hope you are enjoying the " header += dayPart(today) + "." document.write(header) </SCRIPT>


</BODY> </HTML>


      </source>
   
  


Date: date, month, and year.

   <source lang="html4strict">

/* Note that the getMonth method returns 0 in January, 1 in February etc. So add 1 to the getMonth method to display the correct date.

  • /

<html> <body> <script type="text/javascript">

   var d = new Date()
   document.write(d.getDate())
   document.write(".")
   document.write(d.getMonth() + 1)
   document.write(".")
   document.write(d.getFullYear())

</script> </body> </html>


      </source>
   
  


Date: Week of the year

   <source lang="html4strict">

<html> <head> </head> <body> <SCRIPT Language="JavaScript">

   function weekNo() {
       
       var totalDays = 0;
       
       now = new Date();
       years=now.getYear();
   
       var days = new Array(12); 
       days[0] = 31;
       days[2] = 31;
       days[3] = 30;
       days[4] = 31;
       days[5] = 30;
       days[6] = 31;
       days[7] = 31;
       days[8] = 30;
       days[9] = 31;
       days[10] = 30;
       days[11] = 31;

       // is it a leap year
       //////////////////////////////////////////////////
       // has some year 2000 problem 
       // should check the year by dividing 4000
       //
       //////////////////////////////////////////////////
       if (Math.round(now.getYear()/4) == now.getYear()/4) {
           days[1] = 29
       }else{
           days[1] = 28
       }

       // If this is January 
       if (now.getMonth() == 0) { 
           totalDays = totalDays + now.getDate();
       }else{
           var curMonth = now.getMonth();
           for (var count = 1; count <= curMonth; count++) {
               totalDays = totalDays + days[count - 1];
       }
       totalDays = totalDays + now.getDate();
   }
   var agt=navigator.userAgent.toLowerCase();
   
   if ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) {
       var firstday=new Date("01/01/"+String(now.getYear())).getDay();
   }else {
       var firstday=new Date("01/01/"+String(1900+now.getYear())).getDay();
   }
   
   var diff=7-firstday+1;
   var week = Math.round((totalDays+diff-firstday)/7); return week;

} document.write("Week "+weekNo()+" of "+years) </SCRIPT> </body> </html>


      </source>
   
  


Days Before Next Christmas Xmas

   <source lang="html4strict">


function getDaysBeforeNextXmas() {

   var oneMinute = 60 * 1000;
   var oneHour = oneMinute * 60;
   var oneDay = oneHour * 24;
   var today = new Date();
   var nextXmas = new Date();
   nextXmas.setMonth(11);
   nextXmas.setDate(25);
   if (today.getMonth() == 11 && today.getDate() > 25) {
       nextXmas.setFullYear(nextXmas.getFullYear() + 1);
   }
   var diff = nextXmas.getTime() - today.getTime();
   diff = Math.floor(diff/oneDay);
   return diff;

} ...

Only <script type="text/javascript">document.write(getDaysBeforeNextXmas())</script> shopping days until Christmas.

      </source>
   
  


Demo all methods in Date class

   <source lang="html4strict">

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

   <head>
       <title>jsPro - Date</title>
       
       <script type="text/javascript">

/**

* +-------------------------------------------------------------------------+
* | jsPro - Error                                                           |
* +-------------------------------------------------------------------------+
* | Copyright (C) 2001-2003 Stuart Wigley                                   |
* +-------------------------------------------------------------------------+
* | This library is free software; you can redistribute it and/or modify it |
* | under the terms of the GNU Lesser General Public License as published by|
* | the Free Software Foundation; either version 2.1 of the License, or (at |
* | your option) any later version.                                         |
* |                                                                         |
* | This library is distributed in the hope that it will be useful, but     |
* | WITHOUT ANY WARRANTY; without even the implied warranty of              |
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
* | General Public License for more details.                                |
* |                                                                         |
* | You should have received a copy of the GNU Lesser General Public License|
* | along with this library; if not, write to the Free Software Foundation, |
* | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA             |
* +-------------------------------------------------------------------------+
* | Authors:   Stuart Wigley <stuartwigley@yahoo.co.uk>                     |
* |            Randolph Fielding <gator4life@cinci.rr.ru>                  |
* +-------------------------------------------------------------------------+
* $Id: error.js,v 1.15 2003/09/22 04:41:10 gator4life Exp $
*/

/**

* Property used in Error.handleError to specify how errors are
* reported. Permissable values are:
*
* 0    No errors are reported.
* 1    Report the error name and error message using the status bar of the
*      active browser window.
* 2    Report the error name and error message using an alert box.
* 3    Report the error name, error message and debug message using an alert
*      box.
* 4    Report the error name, error message and debug message using a debug
*      window. An instance of the Debug() class must be available.
*/

Error.prototype.debugLevel = 4;

/**

* Uses Error.debugLevel to control how errors are reported. If
* Error.debugLevel is set to 4, you must substitute the name of
* your Debug() instance for oDebug in the line
* var jsProDebugWindow = oDebug.
*
* @summary             handles thrown exceptions
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 09/03/03
* @interface           Error.handleError()
* @requires            Debug.print(vMixedValue, sMessageType)
* @see                 Debug()
* @see                 Debug.print()
*/

Error.prototype.handleError = function() {

   var sDebugMessage = this.debug;
   var sErrorMessage = (sDebugMessage) ? sDebugMessage : "";
   switch (this.debugLevel) {
       case 0 :
           break;
       case 1 :
           window.status = this.name + ": " + this.message;
           break;
       case 2 :
           window.alert(this.name + "\n\n" + this.message);
           break;
       case 3 :
           window.alert(this.name + "\n\n" + this.message + "\n\n" + sErrorMessage);
           break;
       case 4 :
           var jsProDebugWindow = oDebug;
           if (jsProDebugWindow) {
               var oDebugWindow = jsProDebugWindow.debugWindow;
               if (oDebugWindow && !oDebugWindow.closed) {
                   jsProDebugWindow.print(this.name + " " + this.message + " " + sErrorMessage, 1);
               }
           }
   }

}

/**

* Creates an object that is a subclass of Error for handling
* ArrayIndexOutOfBounds exceptions.
*
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 06/27/03
* @interface           new ArrayIndexOutOfBoundsException(sMethodName,
*                      iIndex, iArrayLength)
* @param sMethodName   the name of the method where the exception was thrown
* @param iIndex        the index of a hypothetical array member attempting to
*                      be accessed
* @param iArrayLength  the length of the array
*/

function ArrayIndexOutOfBoundsException(sMethodName, iIndex, iArrayLength) {

   this.name = "ArrayIndexOutOfBoundsException";
   this.message = sMethodName + " has been accessed with an illegal index that is either negative or greater than the size of the array.";
   this.debug = "Attempting to access index " + iIndex.toString() + ", but array has an index range of 0 to " + (iArrayLength - 1).toString() + ".";

} ArrayIndexOutOfBoundsException.prototype = new Error();

/**

* Creates an object that is a subclass of Error for handling IllegalArgument
* exceptions.
*
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 07/24/03
* @interface           new IllegalArgumentException(sMethodName,
*                      vExpectedArgs, iActualArgs)
* @param sMethodName   the name of the method where the exception was thrown
* @param vExpectedArgs the number of arguments expected
* @param iActualArgs   the number of arguments received
*/

function IllegalArgumentException(sMethodName, vExpectedArgs, iActualArgs) {

   this.name = "IllegalArgumentException";
   this.message = sMethodName + " has been passed an illegal number of arguments.";
   this.debug = "Expected " + vExpectedArgs.toString() + " argument(s), but received " + iActualArgs.toString() + " argument(s).";

} IllegalArgumentException.prototype = new Error();

/**

* Creates an object that is a subclass of Error for handling IllegalValue
* exceptions.
*
* @author              Randolph Fielding
* @version             1.0, 09/22/03
* @interface           new IllegalValueException(sMethodName,
*                      sVariableName, vExpectedVal, vActualVal)
* @param sMethodName   the name of the method where the exception was thrown
* @param sVariableName the name of the variable containing the illegal value
* @param vExpectedVal  the value expected in the variable containing the
*                      illegal value
* @param vActualVal    the value currently in the variable containing the
*                      illegal value
*/

function IllegalValueException(sMethodName, sVariableName, vExpectedVal, vActualVal) {

   this.name = "IllegalValueException";
   this.message = sMethodName + " has encountered an illegal value in variable " + sVariableName + "."
   this.debug = "Expected a value of " + vExpectedVal.toString() + ", but contains a value of " + vActualVal.toString() + "."

} IllegalValueException.prototype = new Error();

/**

* Creates an object that is a subclass of Error for handling
* MethodNotAvailable exceptions.
*
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 06/27/03
* @interface           new MethodNotAvailableException(sMethodName,
*                      sMethodNameNA)
* @param sMethodName   the name of the method where the exception was thrown
* @param sMethodNameNA the name of the method that was not available
*/

function MethodNotAvailableException(sMethodName, sMethodNameNA) {

   this.name = "MethodNotAvailableException";
   this.message = "A method has been called that is not available.";
   this.debug = sMethodName + " attempted to call " + sMethodNameNA + ".";

} MethodNotAvailableException.prototype = new Error();

/**

* Creates an object that is a subclass of Error for handling
* PropertyNotAvailable exceptions.
*
* @author              Randolph Fielding
* @version             1.1, 08/01/03
* @interface           new PropertyNotAvailableException(sMethodName,
*                      sPropNameNA)
* @param sMethodName   the name of the method where the exception was thrown
* @param sPropNameNA   the name of the property that was not available
*/

function PropertyNotAvailableException(sMethodName, sPropNameNA) {

   this.name = "PropertyNotAvailableException";
   this.message = "A property has been accessed that is not available.";
   this.debug = sMethodName + " attempted to access " + sPropNameNA + ".";

} PropertyNotAvailableException.prototype = new Error();

/**

* Creates an object that is a subclass of Error for handling TypeMismatch
* exceptions.
*
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 07/24/03
* @interface           new TypeMismatchException(sMethodName,
*                      sExpectedType, sActualType)
* @param sMethodName   the name of the method where the exception was thrown
* @param sExpectedType the name of the expected type of an argument
* @param sActualType   the name of the actual type of an argument
*/

function TypeMismatchException(sMethodName, sExpectedType, sActualType) {

   this.name = "TypeMismatchException";
   this.message = sMethodName + " has been passed an argument with an illegal or inappropriate type.";
   this.debug = "Expected an argument with a type of " + sExpectedType + ", but received an argument with a type of " + sActualType + ".";

} TypeMismatchException.prototype = new Error();

/**

* Creates an object that is a subclass of Error for handling Unknown
* exceptions.
*
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 06/27/03
* @interface           new UnknownException(sMethodName)
* @param sMethodName   the name of the method where the exception was thrown
*/

function UnknownException(sMethodName) {

   this.name = "UnknownException";
   this.message = "An unknown error has occurred in " + sMethodName + ".";

} UnknownException.prototype = new Error();

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

/**

* +-------------------------------------------------------------------------+
* | jsPro - Debug                                                           |
* +-------------------------------------------------------------------------+
* | Copyright (C) 2001-2003 Stuart Wigley                                   |
* +-------------------------------------------------------------------------+
* | This library is free software; you can redistribute it and/or modify it |
* | under the terms of the GNU Lesser General Public License as published by|
* | the Free Software Foundation; either version 2.1 of the License, or (at |
* | your option) any later version.                                         |
* |                                                                         |
* | This library is distributed in the hope that it will be useful, but     |
* | WITHOUT ANY WARRANTY; without even the implied warranty of              |
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
* | General Public License for more details.                                |
* |                                                                         |
* | You should have received a copy of the GNU Lesser General Public License|
* | along with this library; if not, write to the Free Software Foundation, |
* | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA             |
* +-------------------------------------------------------------------------+
* | Authors:   Stuart Wigley <stuartwigley@yahoo.co.uk>                     |
* |            Randolph Fielding <gator4life@cinci.rr.ru>                  |
* +-------------------------------------------------------------------------+
* $Id: debug.js,v 1.6 2003/09/22 05:07:41 gator4life Exp $
*/

/**

* Creates an object that opens a window for debugging.
*
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 09/05/03
* @interface           new Debug()
*/

function Debug() {

   this.debugWindow = window.open("../debug/debug.html", "debug", "width=400,height=600,resizable=yes,scrollbars=yes");

}

/**

* Clears the contents of the debug window.
*
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 09/05/03
* @interface           Debug.clear()
* @return              true if no exceptions are encountered
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
* @throws              UnknownException
*/

Debug.prototype.clear = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments != 0) {
           throw vError = new IllegalArgumentException("Debug.clear", 0, iNumArguments);
       }
       var oMessageContainer = document.getElementById("messageContainer");
       if (!oMessageContainer) {
           throw vError = new UnknownException("Debug.clear");
       }
       while (oMessageContainer.hasChildNodes()) {
           oMessageContainer.removeChild(oMessageContainer.firstChild);
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : true;
   }

}

/**

* Displays content within the debug window.
*
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 09/05/03
* @interface           Debug.print(vMixedValue)
* @interface           Debug.print(vMixedValue, iMessageType)
* @param vMixedValue   content to be displayed within the debug window
* @param iMessageType  an integer representing the type of content to display
*                      within the debug window (information: 0; error: 1)
*                      (optional)
* @return              true if no exceptions are encountered
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
* @throws              IllegalValueException
* @throws              TypeMismatchException
* @throws              UnknownException
*/

Debug.prototype.print = function(vMixedValue) {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       var iMessageType = 0;
       if ((iNumArguments < 1) || (iNumArguments > 2)) {
           throw vError = new IllegalArgumentException("Debug.print", "1 or 2", iNumArguments);
       } else if (iNumArguments == 2) {
           iMessageType = arguments[1];
       }
       if ((typeof iMessageType != "number") || (iMessageType.toString().indexOf(".") != -1)) {
           throw vError = new TypeMismatchException("Debug.print", "integer", typeof iMessageType);
       }
       if ((iMessageType != 0) && (iMessageType != 1)) {
           throw vError = new IllegalValueException("Debug.print", "iMessageType", "0 or 1", iMessageType);
       }
       var oDebugWindow = this.debugWindow;
       if (!oDebugWindow || oDebugWindow.closed) {
           throw vError = new UnknownException("Debug.print");
       }
       var oDocument = oDebugWindow.document;
       if (!oDocument) {
           throw vError = new UnknownException("Debug.print");
       }
       var oMessageContainer = oDocument.getElementById("messageContainer");
       if (!oMessageContainer) {
           throw vError = new UnknownException("Debug.print");
       }
       var oTitleRow = oDocument.createElement("tr");
       var oTitleCell = oDocument.createElement("td");
       var oBodyRow = oDocument.createElement("tr");
       var oBodyCell = oDocument.createElement("td");
       if (!oTitleRow || !oTitleCell || !oBodyRow || !oBodyCell) {
           throw vError = new UnknownException("Debug.print");
       }
       var oTitleRowStyle = oTitleRow.style;
       if (oTitleRowStyle) {
           oTitleRowStyle.backgroundColor = "#EEE";
           oTitleRowStyle.fontWeight = 700;
       }
       var sOutputString = vMixedValue.toString();
       var sTitle = "info";
       var sBody = sOutputString;
       if (iMessageType == 1) {
           sTitle = sOutputString.match(/\w+/);
           sBody = sOutputString.replace(/\w+/, "");
           var oBodyCellStyle = oBodyCell.style;
           if (oBodyCellStyle) {
               oBodyCell.style.backgroundColor = "#FCC";
           }
       }
       oMessageContainer.appendChild(oTitleRow);
       oTitleRow.appendChild(oTitleCell);
       oTitleCell.appendChild(oDocument.createTextNode(sTitle));
       oMessageContainer.appendChild(oBodyRow);
       oBodyRow.appendChild(oBodyCell);
       oBodyCell.appendChild(oDocument.createTextNode(sBody));
       oDebugWindow.focus();
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : true;
   }

}

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

/**

* +-------------------------------------------------------------------------+
* | jsPro - Test                                                            |
* +-------------------------------------------------------------------------+
* | Copyright (C) 2001-2003 Stuart Wigley                                   |
* +-------------------------------------------------------------------------+
* | This library is free software; you can redistribute it and/or modify it |
* | under the terms of the GNU Lesser General Public License as published by|
* | the Free Software Foundation; either version 2.1 of the License, or (at |
* | your option) any later version.                                         |
* |                                                                         |
* | This library is distributed in the hope that it will be useful, but     |
* | WITHOUT ANY WARRANTY; without even the implied warranty of              |
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
* | General Public License for more details.                                |
* |                                                                         |
* | You should have received a copy of the GNU Lesser General Public License|
* | along with this library; if not, write to the Free Software Foundation, |
* | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA             |
* +-------------------------------------------------------------------------+
* | Authors:   Stuart Wigley <stuartwigley@yahoo.co.uk>                     |
* |            Randolph Fielding <gator4life@cinci.rr.ru>                  |
* +-------------------------------------------------------------------------+
* $Id: test.js,v 1.6 2003/09/15 05:07:09 gator4life Exp $
*/

/**

* Creates an object that provides methods for testing all jsPro libraries.
*
* @author              Stuart Wigley
* @version             1.0, 07/24/03
* @interface           new Test()
*/

function Test() { }

/**

* Evaluates and returns the result of a jsPro method using assumptions about
* the structure and ids of HTML elements in the jsPro HTML test files.
*
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/20/03
* @interface           Test.evaluateMethod(oButton, sClass)
* @param oButton       the HTML input-button element that is clicked
* @param sClass        the name of the jsPro class instance being tested
* @return              the result of attempting to evaluate a jsPro method
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
* @throws              TypeMismatchException
*/

Test.prototype.evaluateMethod = function(oButton, sClass) {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments != 2) {
           throw vError = new IllegalArgumentException("Error.evaluateMethod", 2, iNumArguments);
       }
       if (typeof oButton != "object") {
           throw vError = new TypeMismatchException("Error.evaluateMethod", "object", typeof oButton);
       }
       if (typeof sClass != "string") {
           throw vError = new TypeMismatchException("Error.evaluateMethod", "string", typeof sClass);
       }
       var sMethodName = oButton.id;
       var oInput1 = document.getElementById(sMethodName + "1");
       var oInput2 = document.getElementById(sMethodName + "2");
       var oInput3 = document.getElementById(sMethodName + "3");
       var oOutput = document.getElementById(sMethodName + "Result");
       var sArguments = "";
       if (oInput1) {
           var sInput1Value = oInput1.value;
           if (sInput1Value != "") {
               var fInput1Value = parseFloat(sInput1Value);
               sArguments += (isNaN(fInput1Value)) ? "\"" + sInput1Value + "\"" : fInput1Value;
           }
       }
       if (oInput2) {
           var sInput2Value = oInput2.value;
           if (sInput2Value != "") {
               var fInput2Value = parseFloat(sInput2Value);
               sArguments += (isNaN(fInput2Value)) ? ", \"" + sInput2Value + "\"" : ", " + fInput2Value;
           }
       }
       if (oInput3) {
           var sInput3Value = oInput3.value;
           if (sInput3Value != "") {
               var fInput3Value = parseFloat(sInput3Value);
               sArguments += (isNaN(fInput3Value)) ? ", \"" + sInput3Value + "\"" : ", " + fInput3Value;
           }
       }
       var vResult = eval(sClass + "." + sMethodName + "(" + sArguments + ")");
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       if (oOutput) {
           oOutput.value = vResult;
       }
   }

}

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

/**

* +-------------------------------------------------------------------------+
* | jsPro - Date                                                            |
* +-------------------------------------------------------------------------+
* | Copyright (C) 2001-2003 Stuart Wigley                                   |
* +-------------------------------------------------------------------------+
* | This library is free software; you can redistribute it and/or modify it |
* | under the terms of the GNU Lesser General Public License as published by|
* | the Free Software Foundation; either version 2.1 of the License, or (at |
* | your option) any later version.                                         |
* |                                                                         |
* | This library is distributed in the hope that it will be useful, but     |
* | WITHOUT ANY WARRANTY; without even the implied warranty of              |
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
* | General Public License for more details.                                |
* |                                                                         |
* | You should have received a copy of the GNU Lesser General Public License|
* | along with this library; if not, write to the Free Software Foundation, |
* | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA             |
* +-------------------------------------------------------------------------+
* | Authors:   Stuart Wigley <stuartwigley@yahoo.co.uk>                     |
* |            Randolph Fielding <gator4life@cinci.rr.ru>                  |
* +-------------------------------------------------------------------------+
* $Id: date.js,v 1.8 2003/10/01 10:02:14 wigleys Exp $
*/

/**

* Implements the functionality within the date() function of PHP and returns
* this date formatted according to the specified format string. See
* http://www.php.net/manual/en/function.date.php for more information.
*
* The following list of string characters are recognized in the specified
* format string:
*
* a - Lowercase Ante Meridiem/Post Meridiem ("am" or "pm")
* A - Uppercase Ante Meridiem/Post Meridiem ("AM" or "PM")
* B - Swatch Internet Time ("@000" to "@999")
* d - Day of month with leading zeroes ("01" to "31")
* D - Three-letter, shortened name of day of week ("Mon" to "Sun")
* F - Full name of month of year ("January" to "December")
* g - 12-hour format of hour of day without leading zeros ("1" to "12")
* G - 24-hour format of hour of day without leading zeros ("0" to "23")
* h - 12-hour format of hour of day with leading zeros ("01" to "12")
* H - 24-hour format of hour of day with leading zeros ("00" to "23")
* i - Minutes of hour with leading zeros ("00" to "59")
* I - << NOT IMPLEMENTED >>
* j - Day of month without leading zeros ("1" to "31")
* l - Full name of day of week ("Monday" to "Sunday")
* L - Leap year or not? ("1" for true or "0" for false)
* m - Month of year with leading zeros ("01" to "12")
* M - Three-letter, shortened name of month of year ("Jan" to "Dec")
* n - Month of year without leading zeros ("1" to "12")
* O - Greenwich Mean Time (GMT) offset ("[+/-]HHMM")
* r - RFC 822 format (e.g. "Thu, 21 Dec 2000 16:01:07 +0200")
* s - Seconds of minute with leading zeros ("00" to "59")
* S - Ordinal suffix (in English) of day of month ("st", "nd", "rd" or "th")
* t - Days in month ("28" to "31")
* T - << NOT IMPLEMENTED >>
* U - Seconds since the UNIX epoch (1 Jan 1970 00:00:00 GMT)
* w - Day of week ("0" for Sunday to "6" for Saturday)
* W - ISO 8601 week number of year ("01" to "53")
* y - Two-digit year (e.g. "99" or "03")
* Y - Four-digit year (e.g. "1999" or "2003")
* z - Day of year ("1" to "366")
* Z - Greenwich Mean Time (GMT) offset in seconds ("-43200" to "43200")
*
* @summary             format date
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/18/03
* @interface           Date.formatDate(sFormatString)
* @requires            Date.getDayOfYear()
* @requires            Date.getDaysInMonth()
* @requires            Date.getGMTOffset()
* @requires            Date.getLong12Hours()
* @requires            Date.getLong24Hours()
* @requires            Date.getLongDate()
* @requires            Date.getLongDayName()
* @requires            Date.getLongMinutes()
* @requires            Date.getLongMonth()
* @requires            Date.getLongMonthName()
* @requires            Date.getLongSeconds()
* @requires            Date.getMeridiem()
* @requires            Date.getOrdinalSuffix()
* @requires            Date.getRFC822Date()
* @requires            Date.getShort12Hours()
* @requires            Date.getShort24Hours()
* @requires            Date.getShortDayName()
* @requires            Date.getShortMonth()
* @requires            Date.getShortMonthName()
* @requires            Date.getShortYear()
* @requires            Date.getSwatchTime()
* @requires            Date.getTimeSeconds()
* @requires            Date.getTimezone()
* @requires            Date.getTimezoneOffsetSeconds()
* @requires            Date.getWeekOfYear()
* @requires            Date.isDaylightSavingsTime()
* @requires            Date.isLeapYear()
* @param sFormatString the string to format against
* @return              the formatted date string
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
* @throws              MethodNotAvailableException
* @throws              TypeMismatchException
* @throws              UnknownException
* @see                 Date.getDayOfYear()
* @see                 Date.getDaysInMonth()
* @see                 Date.getGMTOffset()
* @see                 Date.getLong12Hours()
* @see                 Date.getLong24Hours()
* @see                 Date.getLongDate()
* @see                 Date.getLongDayName()
* @see                 Date.getLongMinutes()
* @see                 Date.getLongMonth()
* @see                 Date.getLongMonthName()
* @see                 Date.getLongSeconds()
* @see                 Date.getMeridiem()
* @see                 Date.getOrdinalSuffix()
* @see                 Date.getRFC822Date()
* @see                 Date.getShort12Hours()
* @see                 Date.getShort24Hours()
* @see                 Date.getShortDayName()
* @see                 Date.getShortMonth()
* @see                 Date.getShortMonthName()
* @see                 Date.getShortYear()
* @see                 Date.getSwatchTime()
* @see                 Date.getTimeSeconds()
* @see                 Date.getTimezone()
* @see                 Date.getTimezoneOffsetSeconds()
* @see                 Date.getWeekOfYear()
* @see                 Date.isDaylightSavingsTime()
* @see                 Date.isLeapYear()
*/

Date.prototype.formatDate = function(sFormatString) {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (!("getDayOfYear" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getDayOfYear");
       }
       if (!("getDaysInMonth" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getDaysInMonth");
       }
       if (!("getGMTOffset" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getGMTOffset");
       }
       if (!("getLong12Hours" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getLong12Hours");
       }
       if (!("getLong24Hours" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getLong24Hours");
       }
       if (!("getLongDate" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getLongDate");
       }
       if (!("getLongDayName" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getLongDayName");
       }
       if (!("getLongMinutes" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getLongMinutes");
       }
       if (!("getLongMonth" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getLongMonth");
       }
       if (!("getLongMonthName" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getLongMonthName");
       }
       if (!("getLongSeconds" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getLongSeconds");
       }
       if (!("getMeridiem" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getMeridiem");
       }
       if (!("getOrdinalSuffix" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getOrdinalSuffix");
       }
       if (!("getRFC822Date" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getRFC822Date");
       }
       if (!("getShort12Hours" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getShort12Hours");
       }
       if (!("getShort24Hours" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getShort24Hours");
       }
       if (!("getShortDayName" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getShortDayName");
       }
       if (!("getShortMonth" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getShortMonth");
       }
       if (!("getShortMonthName" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getShortMonthName");
       }
       if (!("getShortYear" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getShortYear");
       }
       if (!("getSwatchTime" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getSwatchTime");
       }
       if (!("getTimeSeconds" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getTimeSeconds");
       }
       if (!("getTimezone" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getTimezone");
       }
       if (!("getTimezoneOffsetSeconds" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getTimezoneOffsetSeconds");
       }
       if (!("getWeekOfYear" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.getWeekOfYear");
       }
       if (!("isDaylightSavingsTime" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.isDaylightSavingsTime");
       }
       if (!("isLeapYear" in this)) {
           throw vError = new MethodNotAvailableException("Date.formatDate", "Date.isLeapYear");
       }
       if (iNumArguments != 1) {
           throw vError = new IllegalArgumentException("Date.formatDate", 1, iNumArguments);
       }
       if (typeof sFormatString != "string") {
           throw vError = new TypeMismatchException("Date.formatDate", "string", typeof sFormatString);
       }
       var sDayOfYear = this.getDayOfYear();
       var sDaysInMonth = this.getDaysInMonth();
       var sGMTOffset = this.getGMTOffset();
       var sIsDaylightSavingsTime = this.isDaylightSavingsTime();
       var sIsLeapYear = this.isLeapYear();
       var sLong12Hours = this.getLong12Hours();
       var sLong24Hours = this.getLong24Hours();
       var sLongDate = this.getLongDate();
       var sLongDayName = this.getLongDayName();
       var sLongMinutes = this.getLongMinutes();
       var sLongMonth = this.getLongMonth();
       var sLongMonthName = this.getLongMonthName();
       var sLongSeconds = this.getLongSeconds();
       var sMeridiem = this.getMeridiem();
       var sOrdinalSuffix = this.getOrdinalSuffix();
       var sRFC822Date = this.getRFC822Date();
       var sShort12Hours = this.getShort12Hours();
       var sShort24Hours = this.getShort24Hours();
       var sShortDayName = this.getShortDayName();
       var sShortMonth = this.getShortMonth();
       var sShortMonthName = this.getShortMonthName();
       var sShortYear = this.getShortYear();
       var sSwatchTime = this.getSwatchTime();
       var sTimeSeconds = this.getTimeSeconds();
       var sTimezone = this.getTimezone();
       var sTimezoneOffsetSeconds = this.getTimezoneOffsetSeconds();
       var sWeekOfYear = this.getWeekOfYear();
       if (!sDayOfYear      || !sDaysInMonth           || !sGMTOffset     || !sIsDaylightSavingsTime ||
           !sIsLeapYear     || !sLong12Hours           || !sLong24Hours   || !sLongDate              ||
           !sLongDayName    || !sLongMinutes           || !sLongMonth     || !sLongMonthName         ||
           !sLongSeconds    || !sMeridiem              || !sOrdinalSuffix || !sRFC822Date            ||
           !sShort12Hours   || !sShort24Hours          || !sShortDayName  || !sShortMonth            ||
           !sShortMonthName || !sShortYear             || !sSwatchTime    || !sTimeSeconds           ||
           !sTimezone       || !sTimezoneOffsetSeconds || !sWeekOfYear) {
           throw vError = new UnknownException("Date.formatDate");
       }
       var sFormatStringLength = sFormatString.length;
       var sFormattedDate = "";
       for (var i = 0; i < sFormatStringLength; i++) {
           var sChar = sFormatString.charAt(i);
           switch (sChar) {
               case "a" : sFormattedDate += sMeridiem; break;
               case "A" : sFormattedDate += sMeridiem.toUpperCase(); break;
               case "B" : sFormattedDate += sSwatchTime; break;
               case "d" : sFormattedDate += sLongDate; break;
               case "D" : sFormattedDate += sShortDayName; break;
               case "F" : sFormattedDate += sLongMonthName; break;
               case "g" : sFormattedDate += sShort12Hours; break;
               case "G" : sFormattedDate += sShort24Hours; break;
               case "h" : sFormattedDate += sLong12Hours; break;
               case "H" : sFormattedDate += sLong24Hours; break;
               case "i" : sFormattedDate += sLongMinutes; break;
               case "I" : sFormattedDate += sIsDaylightSavingsTime; break;
               case "j" : sFormattedDate += this.getDate().toString(); break;
               case "l" : sFormattedDate += sLongDayName; break;
               case "L" : sFormattedDate += sIsLeapYear; break;
               case "m" : sFormattedDate += sLongMonth; break;
               case "M" : sFormattedDate += sShortMonthName; break;
               case "n" : sFormattedDate += sShortMonth; break;
               case "O" : sFormattedDate += sGMTOffset; break;
               case "r" : sFormattedDate += sRFC822Date; break;
               case "s" : sFormattedDate += sLongSeconds; break;
               case "S" : sFormattedDate += sOrdinalSuffix; break;
               case "t" : sFormattedDate += sDaysInMonth; break;
               case "T" : sFormattedDate += sTimezone; break;
               case "U" : sFormattedDate += sTimeSeconds; break;
               case "w" : sFormattedDate += this.getDay().toString(); break;
               case "W" : sFormattedDate += sWeekOfYear; break;
               case "y" : sFormattedDate += sShortYear; break;
               case "Y" : sFormattedDate += this.getFullYear().toString(); break;
               case "z" : sFormattedDate += sDayOfYear; break;
               case "Z" : sFormattedDate += sTimezoneOffsetSeconds; break;
               default  : sFormattedDate += sChar;
           }
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sFormattedDate;
   }

}

/**

* Returns the day of the year for this date as a one-, two-, or three-digit
* string between "1" and "366", inclusive.
*
* @summary             day of year
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/12/03
* @interface           Date.getDayOfYear()
* @requires            Date.isLeapYear()
* @return              the day of the year for this date as a one-, two-, or
*                      three-digit string between "1" and "366", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
* @throws              MethodNotAvailableException
* @throws              UnknownException
* @see                 Date.isLeapYear()
*/

Date.prototype.getDayOfYear = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (!("isLeapYear" in this)) {
           throw vError = new MethodNotAvailableException("Date.getDayOfYear", "Date.isLeapYear");
       }
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getDayOfYear", 0, iNumArguments);
       }
       var iMonth = this.getMonth();
       var sIsLeapYear = this.isLeapYear();
       if (!sIsLeapYear) {
           throw vError = new UnknownException("Date.getDayOfYear");
       }
       var iDaysInFebruary = (parseInt(sIsLeapYear) == 1) ? 29 : 28;
       var aDaysInMonth = new Array(31, iDaysInFebruary, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
       var iDayOfYear = 0;
       for (var i = 0; i < iMonth; i++) {
           iDayOfYear += aDaysInMonth[i];
       }
       iDayOfYear += this.getDate();
       var sDayOfYear = iDayOfYear.toString();
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sDayOfYear;
   }

}

/**

* Returns the number of days in the month for this date as a two-digit string
* between "28" and "31", inclusive.
*
* @summary             days in month
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getDaysInMonth()
* @requires            Date.isLeapYear()
* @return              the number of days in the month for this date as a
*                      two-digit string between "28" and "31", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
* @throws              MethodNotAvailableException
* @throws              UnknownException
* @see                 Date.isLeapYear()
*/

Date.prototype.getDaysInMonth = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (!("isLeapYear" in this)) {
           throw vError = new MethodNotAvailableException("Date.getDaysInMonth", "Date.isLeapYear");
       }
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getDaysInMonth", 0, iNumArguments);
       }
       var iMonth = this.getMonth();
       var sIsLeapYear = this.isLeapYear();
       if (!sIsLeapYear) {
           throw vError = new UnknownException("Date.getDaysInMonth");
       }
       switch (iMonth) {
           case  1 : var iDaysInMonth = (parseInt(sIsLeapYear) == 1) ? 29 : 28; break;
           case  3 :
           case  5 :
           case  8 :
           case 10 : var iDaysInMonth = 30; break;
           default : var iDaysInMonth = 31;
       }
       var sDaysInMonth = iDaysInMonth.toString();
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sDaysInMonth;
   }

}

/**

* Returns the number of days in the year for this date as either 365 or 366.
*
* @summary             days in year
* @author              Stuart Wigley
* @version             1.0, 12/01/03
* @interface           Date.getDaysInYear()
* @requires            Date.isLeapYear()
* @return              the number of days in the year for this date as either
*                      365 or 366
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
* @throws              MethodNotAvailableException
* @throws              UnknownException
* @see                 Date.isLeapYear()
*/

Date.prototype.getDaysInYear = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (!("isLeapYear" in this)) {
           throw vError = new MethodNotAvailableException("Date.getDaysInYear", "Date.isLeapYear");
       }
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getDaysInYear", 0, iNumArguments);
       }
       var sIsLeapYear = this.isLeapYear();
       if (!sIsLeapYear) {
           throw vError = new UnknownException("Date.getDaysInYear");
       }
       var sDaysInYear = (sIsLeapYear == "1") ? "366" : "365";
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sDaysInYear;
   }

}

/**

* Calculates the day on which Easter Sunday falls for the current year using
* Butcher"s Method. Returns an integer between "1" and "31"
*
* @summary             easter day
* @author              Stuart Wigley
* @version             1.0, 12/01/03
* @interface           Date.getEasterDay()
* @return              the day on which Easter Sunday falls
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getEasterDay = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getEasterDate", 0, iNumArguments);
       }
       var iYear = this.getFullYear();
       var a = iYear % 19;
       var b = Math.floor(iYear / 100);
       var c = iYear % 100;
       var d = Math.floor(b / 4);
       var e = b % 4;
       var f = Math.floor((b + 8) / 25);
       var g = Math.floor((b - f + 1) / 3);
       var h = (19 * a + b - d - g + 15) % 30;
       var i = Math.floor(c / 4);
       var k = c % 4;
       var l = (32 + 2 * e + 2 * i - h - k) % 7;
       var m = Math.floor((a + 11 * h + 22 * l) / 451);
       var p = (h + l - 7 * m + 114) % 31;
       var iEasterDay = p + 1;
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : iEasterDay;
   }

}

/**

* Calculates the month in which Easter Sunday falls for the current year using
* Butcher"s Method. Returns "3" for March or "4" for April.
*
* @summary             easter month
* @author              Stuart Wigley
* @version             1.0, 12/01/03
* @interface           Date.getEasterMonth()
* @return              the month in which Easter Sunday falls
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getEasterMonth = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getEasterMonth", 0, iNumArguments);
       }
       var iYear = this.getFullYear();
       var a = iYear % 19;
       var b = Math.floor(iYear / 100);
       var c = iYear % 100;
       var d = Math.floor(b / 4);
       var e = b % 4;
       var f = Math.floor((b + 8) / 25);
       var g = Math.floor((b - f + 1) / 3);
       var h = (19 * a + b - d - g + 15) % 30;
       var i = Math.floor(c / 4);
       var k = c % 4;
       var l = (32 + 2 * e + 2 * i - h - k) % 7;
       var m = Math.floor((a + 11 * h + 22 * l) / 451);
       var iEasterMonth = Math.floor((h + l - 7 * m + 114) / 31);
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : iEasterMonth;
   }

}

/**

* Returns the formatted Greenwich Mean Time (GMT) offset ("[+/-]HHMM") for
* this date that consists of a plus sign (+) or minus sign (-) followed by
* four digits representing hours (HH) and minutes (MM).
*
* @summary             GMT offset
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 08/17/03
* @interface           Date.getGMTOffset()
* @return              the formatted Greenwich Mean Time (GMT) offset
*                      ("[+/-]HHMM") for this date
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getGMTOffset = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getGMTOffset", 0, iNumArguments);
       }
       var iTimezoneOffset = this.getTimezoneOffset();
       var iAbsTimezoneOffset = Math.abs(iTimezoneOffset);
       var sTimezoneOffsetSign = (iTimezoneOffset != iAbsTimezoneOffset) ? "-" : "+";
       var iTimezoneOffsetHours = iAbsTimezoneOffset / 60;
       var sTempTimezoneOffsetHours = iTimezoneOffsetHours.toString();
       var sTimezoneOffsetHours = (iTimezoneOffsetHours < 10) ? "0" + sTempTimezoneOffsetHours : sTempTimezoneOffsetHours;
       var iTimezoneOffsetMinutes = iAbsTimezoneOffset % 60;
       var sTempTimezoneOffsetMinutes = iTimezoneOffsetMinutes.toString();
       var sTimezoneOffsetMinutes = (iTimezoneOffsetMinutes < 10) ? "0" + sTempTimezoneOffsetMinutes : sTempTimezoneOffsetMinutes;
       var sGMTOffset = sTimezoneOffsetSign + sTimezoneOffsetHours + sTimezoneOffsetMinutes;
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sGMTOffset;
   }

}

/**

* Returns the hour for this date as a two-digit string between "01" and "12",
* inclusive.
*
* @summary             12-hour two-digit hour (01-12)
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getLong12Hours()
* @return              the hour for this date as a two-digit string between
*                      "01" and "12", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getLong12Hours = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getLong12Hours", 0, iNumArguments);
       }
       var iShort12Hours = this.getHours() % 12;
       var sLong12Hours = iShort12Hours.toString();
       if (iShort12Hours == 0) {
           sLong12Hours = "12";
       } else if (iShort12Hours < 10) {
           sLong12Hours = "0" + sLong12Hours;
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sLong12Hours;
   }

}

/**

* Returns the hour for this date as a two-digit string between "00" and "23",
* inclusive.
*
* @summary             24-hour two-digit hour (00-23)
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getLong24Hours()
* @return              the hour for this date as a two-digit string between
*                      "00" and "23", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getLong24Hours = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getLong24Hours", 0, iNumArguments);
       }
       var iShort24Hours = this.getHours();
       var sLong24Hours = iShort24Hours.toString();
       if (iShort24Hours < 10) {
           sLong24Hours = "0" + sLong24Hours;
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sLong24Hours;
   }

}

/**

* Returns the day of the month for this date as a two-digit string between
* "01" and "31", inclusive.
*
* @summary             two-digit day of month (01-31)
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 08/17/03
* @interface           Date.getLongDate()
* @return              the day of the month for this date as a two-digit
*                      string between "01" and "31", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getLongDate = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getLongDate", 0, iNumArguments);
       }
       var iShortDate = this.getDate();
       var sLongDate = iShortDate.toString();
       if (iShortDate < 10) {
           sLongDate = "0" + sLongDate;
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sLongDate;
   }

}

/**

* Returns the day name for this date (e.g. "Monday", "Tuesday", etc.).
*
* @summary             day name
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getLongDayName()
* @return              the day name for this date
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getLongDayName = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getLongDayName", 0, iNumArguments);
       }
       var aLongDayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
       var sLongDayName = aLongDayNames[this.getDay()];
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sLongDayName;
   }

}

/**

* Returns the minutes for this date as a two-digit string between "00" and
* "59", inclusive.
*
* @summary             two-digit minutes (00-59)
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 08/17/03
* @interface           Date.getLongMinutes()
* @return              the minutes for this date as a two-digit string
*                      between "00" and "59", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getLongMinutes = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getLongMinutes", 0, iNumArguments);
       }
       var iShortMinutes = this.getMinutes();
       var sLongMinutes = iShortMinutes.toString();
       if (iShortMinutes < 10) {
           sLongMinutes = "0" + sLongMinutes;
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sLongMinutes;
   }

}

/**

* Returns the month for this date as a two-digit string between "01" and
* "12", inclusive.
*
* @summary             two-digit month (01-12)
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 08/17/03
* @interface           Date.getLongMonth()
* @return              the month for this date as a two-digit string between
*                      "01" and "12", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getLongMonth = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getLongMonth", 0, iNumArguments);
       }
       var iShortMonth = this.getMonth() + 1;
       var sLongMonth = iShortMonth.toString();
       if (iShortMonth < 10) {
           sLongMonth = "0" + sLongMonth;
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sLongMonth;
   }

}

/**

* Returns the month name for this date (e.g. "January", "February", etc.).
*
* @summary             month name
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getLongMonthName()
* @return              the month name for this date
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getLongMonthName = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getLongMonthName", 0, iNumArguments);
       }
       var aLongMonthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
       var sLongMonthName = aLongMonthNames[this.getMonth()];
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sLongMonthName;
   }

}

/**

* Returns the seconds for this date as a two-digit string between "00" and
* "59", inclusive.
*
* @summary             two-digit seconds (00-59)
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 08/17/03
* @interface           Date.getLongSeconds()
* @return              the seconds for this date as a two-digit string
*                      between "00" and "59", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getLongSeconds = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getLongSeconds", 0, iNumArguments);
       }
       var iShortSeconds = this.getSeconds();
       var sLongSeconds = iShortSeconds.toString();
       if (iShortSeconds < 10) {
           sLongSeconds = "0" + sLongSeconds;
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sLongSeconds;
   }

}

/**

* Returns the "meridiem" for this date as either "am" (Ante Meridiem) or "pm"
* (Post Meridiem).
*
* @summary             meridiem
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getMeridiem()
* @return              the "meridiem" for this date as either "am" or "pm"
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getMeridiem = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getMeridiem", 0, iNumArguments);
       }
       var sMeridiem = (this.getHours() < 12) ? "am" : "pm";
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sMeridiem;
   }

}

/**

* Returns the ordinal suffix (in English) of the day of the month for this
* date (i.e. "st", "nd", "rd" or "th").
*
* @summary             English ordinal suffix
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getOrdinalSuffix()
* @return              the ordinal suffix (in English) of the day of the
*                      month for this date (i.e. "st", "nd", "rd" or "th")
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getOrdinalSuffix = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getOrdinalSuffix", 0, iNumArguments);
       }
       switch (this.getDate()) {
           case  1 :
           case 21 :
           case 31 : var sOrdinalSuffix = "st"; break;
           case  2 :
           case 22 : var sOrdinalSuffix = "nd"; break;
           case  3 :
           case 23 : var sOrdinalSuffix = "rd"; break;
           default : var sOrdinalSuffix = "th";
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sOrdinalSuffix;
   }

}

/**

* Returns this date formatted according to the Date and Time Specification of
* RFC 822 (Standard for the Format of ARPA Internet Text Messages).
*
* @summary             RFC 822 date
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getRFC822Date()
* @requires            Date.getGMTOffset()
* @requires            Date.getLong24Hours()
* @requires            Date.getLongMinutes()
* @requires            Date.getLongSeconds()
* @requires            Date.getShortDayName()
* @requires            Date.getShortMonthName()
* @return              this date formatted according to the Date and Time
*                      Specification of RFC 822
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
* @throws              MethodNotAvailableException
* @throws              UnknownException
* @see                 Date.getGMTOffset()
* @see                 Date.getLong24Hours()
* @see                 Date.getLongMinutes()
* @see                 Date.getLongSeconds()
* @see                 Date.getShortDayName()
* @see                 Date.getShortMonthName()
*/

Date.prototype.getRFC822Date = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (!("getGMTOffset" in this)) {
           throw vError = new MethodNotAvailableException("Date.getRFC822Date", "Date.getGMTOffset");
       }
       if (!("getLong24Hours" in this)) {
           throw vError = new MethodNotAvailableException("Date.getRFC822Date", "Date.getLong24Hours");
       }
       if (!("getLongMinutes" in this)) {
           throw vError = new MethodNotAvailableException("Date.getRFC822Date", "Date.getLongMinutes");
       }
       if (!("getLongSeconds" in this)) {
           throw vError = new MethodNotAvailableException("Date.getRFC822Date", "Date.getLongSeconds");
       }
       if (!("getShortDayName" in this)) {
           throw vError = new MethodNotAvailableException("Date.getRFC822Date", "Date.getShortDayName");
       }
       if (!("getShortMonthName" in this)) {
           throw vError = new MethodNotAvailableException("Date.getRFC822Date", "Date.getShortMonthName");
       }
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getRFC822Date", 0, iNumArguments);
       }
       var sGMTOffset = this.getGMTOffset();
       var sLong24Hours = this.getLong24Hours();
       var sLongMinutes = this.getLongMinutes();
       var sLongSeconds = this.getLongSeconds();
       var sShortDayName = this.getShortDayName();
       var sShortMonthName = this.getShortMonthName();
       if (!sGMTOffset || !sLong24Hours || !sLongMinutes || !sLongSeconds || !sShortDayName || !sShortMonthName) {
           throw vError = new UnknownException("Date.getRFC822Date");
       }
       var sRFC822Date = sShortDayName + ", " + this.getDate() + " " + sShortMonthName + " " + this.getFullYear() + " " + sLong24Hours + ":" + sLongMinutes + ":" + sLongSeconds + " " + sGMTOffset;
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sRFC822Date;
   }

}

/**

* Returns the hour for this date as a one- or two-digit string between "1"
* and "12", inclusive.
*
* @summary             12-hour one-/two-digit hour (1-12)
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getShort12Hours()
* @return              the hour for this date as a one- or two-digit string
*                      between "1" and "12", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getShort12Hours = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getShort12Hours", 0, iNumArguments);
       }
       var iTempShort12Hours = this.getHours() % 12;
       var sShort12Hours = ((iTempShort12Hours == 0) ? 12 : iTempShort12Hours).toString();
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sShort12Hours;
   }

}

/**

* Returns the hour for this date as a one- or two-digit string between "0"
* and "23", inclusive.
*
* @summary             24-hour one-/two-digit hour (0-23)
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getShort24Hours()
* @return              the hour for this date as a one- or two-digit string
*                      between "0" and "23", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getShort24Hours = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getShort24Hours", 0, iNumArguments);
       }
       var sShort24Hours = this.getHours().toString();
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sShort24Hours;
   }

}

/**

* Returns the shortened day name for this date (e.g. "Mon", "Tue", etc.).
*
* @summary             short day name
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getShortDayName()
* @requires            Date.getLongDayName()
* @return              the shortened day name for this date
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
* @throws              MethodNotAvailableException
* @throws              UnknownException
* @see                 Date.getLongDayName()
*/

Date.prototype.getShortDayName = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (!("getLongDayName" in this)) {
           throw vError = new MethodNotAvailableException("Date.getShortDayName", "Date.getLongDayName");
       }
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getShortDayName", 0, iNumArguments);
       }
       var sLongDayName = this.getLongDayName();
       if (!sLongDayName) {
           throw vError = new UnknownException("Date.getShortDayName");
       }
       var sShortDayName = sLongDayName.substr(0, 3);
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sShortDayName;
   }

}

/**

* Returns the month for this date as a one- or two-digit string between "1"
* and "12", inclusive.
*
* @summary             one-/two-digit month (1-12)
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 08/17/03
* @interface           Date.getShortMonth()
* @return              the month for this date as a one- or two-digit string
*                      between "1" and "12", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getShortMonth = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getShortMonth", 0, iNumArguments);
       }
       var sShortMonth = (this.getMonth() + 1).toString();
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sShortMonth;
   }

}

/**

* Returns the shortened month name for this date (e.g. "Jan", "Feb", etc.).
*
* @summary             short month name
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/17/03
* @interface           Date.getShortMonthName()
* @requires            Date.getLongMonthName()
* @return              the shortened month name for this date
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
* @throws              MethodNotAvailableException
* @throws              UnknownException
* @see                 Date.getLongMonthName()
*/

Date.prototype.getShortMonthName = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (!("getLongMonthName" in this)) {
           throw vError = new MethodNotAvailableException("Date.getShortMonthName", "Date.getLongMonthName");
       }
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getShortMonthName", 0, iNumArguments);
       }
       var sLongMonthName = this.getLongMonthName();
       if (!sLongMonthName) {
           throw vError = new UnknownException("Date.getShortMonthName");
       }
       var sShortMonthName = sLongMonthName.substr(0, 3);
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sShortMonthName;
   }

}

/**

* Returns the year for this date as a two-digit string between "00" and "99",
* inclusive.
*
* @summary             two-digit year (00-99)
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 08/17/03
* @interface           Date.getShortYear()
* @return              the year for this date as a two-digit string between
*                      "00" and "99", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getShortYear = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getShortYear", 0, iNumArguments);
       }
       var sShortYear = this.getFullYear().toString().substr(2);
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sShortYear;
   }

}

/**

* Returns the Swatch Internet Time for this date as a three-digit string
* between "000" and "999" prefixed by "@". See http://www.swatch.ru for more
* information.
*
* @summary             Swatch Internet Time
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/18/03
* @interface           Date.getSwatchTime()
* @return              the Swatch Internet Time for this date as a three-
*                      digit string between "000" and "999" prefixed by "@"
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getSwatchTime = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getSwatchTime", 0, iNumArguments);
       }
       var iTempSwatchTime = Math.floor(((this.getHours() * 3600) + ((this.getMinutes() + this.getTimezoneOffset() + 60) * 60) + this.getSeconds()) / 86.4);
       var iSwatchTime = (iTempSwatchTime >= 1000) ? iTempSwatchTime - 1000 : iTempSwatchTime;
       var sSwatchTime = iSwatchTime.toString();
       if (iSwatchTime < 10) {
           sSwatchTime = "@00" + sSwatchTime;
       } else if (iSwatchTime < 100) {
           sSwatchTime = "@0" + sSwatchTime;
       } else {
           sSwatchTime = "@" + sSwatchTime;
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sSwatchTime;
   }

} /**

* Returns the number of seconds elapsed since the UNIX epoch (1 Jan 1970
* 00:00:00 GMT) for this date.
*
* @summary             seconds since UNIX epoch
* @author              Randolph Fielding
* @version             1.0, 08/20/03
* @interface           Date.getTimeSeconds()
* @return              the number of seconds elapsed since the UNIX epoch (1
*                      Jan 1970 00:00:00 GMT) for this date
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getTimeSeconds = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getTimeSeconds", 0, iNumArguments);
       }
       var sTimeSeconds = Math.floor(this.getTime() / 1000).toString();
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sTimeSeconds;
   }

}

/**

* Returns the abbreviation of the name of the local timezone.
*
* @summary             not implemented
* @author              Stuart Wigley
* @version             1.0, 08/07/03
* @interface           Date.getTimezone()
* @return              the abbreviation of the name of the local timezone
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getTimezone = function() {

   return "<< NOT IMPLEMENTED >>";

}

/**

* Returns the Greenwich Mean Time (GMT) offset for this date in seconds.
*
* @summary             timezone offset in seconds
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.2, 08/17/03
* @interface           Date.getTimezoneOffsetSeconds()
* @return              the Greenwich Mean Time (GMT) offset for this date in
*                      seconds
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getTimezoneOffsetSeconds = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getTimezoneOffsetSeconds", 0, iNumArguments);
       }
       var sTimezoneOffsetSeconds = (this.getTimezoneOffset() * 60).toString();
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sTimezoneOffsetSeconds;
   }

}

/**

* Returns the ISO week (as specified in the ISO 8601 calendar) for this date
* as a two-digit string between "01" and "53", inclusive. The algorithm used
* is adopted from "Algorithm for Converting Gregorian Dates to ISO 8601 Week
* Date (Y2K Compliant)" by Rick McCarty, 1999. See
* http://personal.ecu.edu/mccartyr/ISOwdALG.txt for more information.
*
* @summary             week of year
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/25/03
* @interface           Date.getWeekOfYear()
* @requires            Date.getDayOfYear()
* @requires            Date.isLeapYear()
* @return              the ISO week for this date as a one- or two-digit
*                      string between "1" and "53", inclusive
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
* @throws              MethodNotAvailableException
* @throws              UnknownException
* @throws              Date.getDayOfYear()
* @see                 Date.isLeapYear()
*/

Date.prototype.getWeekOfYear = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (!("getDayOfYear" in this)) {
           throw vError = new MethodNotAvailableException("Date.getWeekOfYear", "Date.getDayOfYear");
       }
       if (!("isLeapYear" in this)) {
           throw vError = new MethodNotAvailableException("Date.getWeekOfYear", "Date.isLeapYear");
       }
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getWeekOfYear", 0, iNumArguments);
       }
       var iYear = this.getFullYear();
       var iYearM1 = iYear - 1;
       var sDayOfYear = this.getDayOfYear();
       var sIsLeapYear = this.isLeapYear();
       var sIsLeapYearM1 = (new Date("January 1, " + iYearM1.toString())).isLeapYear();
       if (!sDayOfYear || !sIsLeapYear || !sIsLeapYearM1) {
           throw vError = new UnknownException("Date.getWeekOfYear");
       }
       var iYearM1Mod100 = iYearM1 % 100;
       var iDayOfYear = parseInt(sDayOfYear);
       var iJan1DayOfWeek = 1 + ((((Math.floor((iYearM1 - iYearM1Mod100) / 100) % 4) * 5) + (iYearM1Mod100 + Math.floor(iYearM1Mod100 / 4))) % 7);
       var iDayOfWeek = 1 + (((iDayOfYear + (iJan1DayOfWeek - 1)) - 1) % 7);
       var iDaysInYear = (parseInt(sIsLeapYear) == 1) ? 366 : 365;
       var iWeekOfYear = 0;
       if ((iDayOfYear <= (8 - iJan1DayOfWeek)) && (iJan1DayOfWeek > 4)) {
           iWeekOfYear = ((iJan1DayOfWeek == 5) || ((iJan1DayOfWeek == 6) && (parseInt(sIsLeapYearM1) == 1))) ? 53 : 52;
       } else if ((iDaysInYear - iDayOfYear) < (4 - iDayOfWeek)) {
           iWeekOfYear = 1;
       } else {
           iWeekOfYear = Math.floor((iDayOfYear + (7 - iDayOfWeek) + (iJan1DayOfWeek - 1)) / 7);
           if (iJan1DayOfWeek > 4) {
               iWeekOfYear -= 1;
           }
       }
       var sWeekOfYear = iWeekOfYear.toString();
       if (iWeekOfYear < 10) {
           sWeekOfYear = "0" + sWeekOfYear;
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sWeekOfYear;
   }

}

/**

* Returns Zodiac sign for the current date.
*
* @summary             zodiac sign
* @author              Stuart Wigley
* @version             1.0, 10/01/03
* @interface           Date.getZodiacSign()
* @return              the Zodiac sign for the current date
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.getZodiacSign = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.getZodiac", 0, iNumArguments);
       }
       var iMonth = this.getMonth() + 1;
       var iDay = this.getDate();
       var sZodiacSign = "";
       if (iMonth == 1 && iDay >= 20 || iMonth == 2 && iDay <=18) {
           sZodiacSign = "Aquarius";
       } else if (iMonth == 2 && iDay >=19 || iMonth == 3 && iDay <=20) {
           sZodiacSign = "Pisces";
       } else if (iMonth == 3 && iDay >=21 || iMonth == 4 && iDay <=19) {
           sZodiacSign = "Aries";
       } else if (iMonth == 4 && iDay >=20 || iMonth == 5 && iDay <=20) {
           sZodiacSign = "Taurus";
       } else if (iMonth == 5 && iDay >=21 || iMonth == 6 && iDay <=21) {
           sZodiacSign = "Gemini";
       } else if (iMonth == 6 && iDay >=22 || iMonth == 7 && iDay <=22) {
           sZodiacSign = "Cancer";
       } else if (iMonth == 7 && iDay >=23 || iMonth == 8 && iDay <=22) {
           sZodiacSign = "Leo";
       } else if (iMonth == 8 && iDay >=23 || iMonth == 9 && iDay <=22) {
           sZodiacSign = "Virgo";
       } else if (iMonth == 9 && iDay >=23 || iMonth == 10 && iDay <=22) {
           sZodiacSign = "Libra";
       } else if (iMonth == 10 && iDay >=23 || iMonth == 11 && iDay <=21) {
           sZodiacSign = "Scorpio";
       } else if (iMonth == 11 && iDay >=22 || iMonth == 12 && iDay <=21) {
           sZodiacSign = "Sagittarius";
       } else if (iMonth == 12 && iDay >=22 || iMonth == 1 && iDay <=19) {
           sZodiacSign = "Capricorn";
       }
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sZodiacSign;
   }

}

/**

* Determines if this date falls within Daylight Savings Time.
*
* @summary             not implemented
* @author              Stuart Wigley
* @version             1.0, 08/07/03
* @interface           Date.isDaylightSavingsTime()
* @return              "1" if this date falls within Daylight Savings Time
* @return              "0" if this date does not fall within Daylight Savings
*                      Time
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.isDaylightSavingsTime = function() {

   return "<< NOT IMPLEMENTED >>";

}

/**

* Determines if this date falls within a leap year.
*
* @summary             is leap year?
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/08/03
* @interface           Date.isLeapYear()
* @return              "1" if this date falls within a leap year
* @return              "0" if this date does not fall within a leap year
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.isLeapYear = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.isLeapYear", 0, iNumArguments);
       }
       var iFullYear = this.getFullYear();
       var sIsLeapYear = (((iFullYear % 4) == 0) && (((iFullYear % 100) != 0) || ((iFullYear % 400) == 0))) ? "1" : "0";
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sIsLeapYear;
   }

}

/**

* Determines if the current day is a weekday in the range Monday to Friday.
*
* @summary             is weekday?
* @author              Stuart Wigley
* @version             1.0, 10/01/03
* @interface           Date.isWeekday()
* @return              "1" if the day is a weekday
* @return              "0" if the day is not a weekday
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.isWeekday = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.isWeekday", 0, iNumArguments);
       }
       var iDayOfWeek = this.getDay();
       var sIsWeekDay = (iDayOfWeek > 0 && iDayOfWeek < 6) ? "1" : "0";
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sIsWeekDay;
   }

}

/**

* Determines if the current day is a weekend ie Saturday or Sunday
*
* @summary             is weekend?
* @author              Stuart Wigley
* @version             1.0, 10/01/03
* @interface           Date.isWeekend()
* @return              "1" if the day is a weekend
* @return              "0" if the day is not a weekend
* @return              null if an exception is encountered
* @throws              IllegalArgumentException
*/

Date.prototype.isWeekend = function() {

   try {
       var vError = null;
       var iNumArguments = arguments.length;
       if (iNumArguments > 0) {
           throw vError = new IllegalArgumentException("Date.isWeekend", 0, iNumArguments);
       }
       var iDayOfWeek = this.getDay();
       var sIsWeekEnd = (iDayOfWeek == 0 || iDayOfWeek == 6) ? "1" : "0";
   }
   catch (vError) {
       if (vError instanceof Error) {
           vError.handleError();
       }
   }
   finally {
       return vError ? null : sIsWeekEnd;
   }

}

       </script>        
       <script type="text/javascript">
           var oTest = new Test();
           var oDebug = new Debug();
           var oDate = new Date();
       </script>
   </head>
   <body>
<tbody> </tbody>
Date.formatDate() <input id="formatDate1" name="input" type="text" size="5" /> <input id="formatDate" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="formatDateResult" name="output" type="text" size="30" readonly="readonly" />
Date.getDayOfYear()   <input id="getDayOfYear" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getDayOfYearResult" name="output" type="text" size="30" readonly="readonly" />
Date.getDaysInMonth()   <input id="getDaysInMonth" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getDaysInMonthResult" name="output" type="text" size="30" readonly="readonly" />
Date.getDaysInYear()   <input id="getDaysInYear" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getDaysInYearResult" name="output" type="text" size="30" readonly="readonly" />
Date.getEasterDay()   <input id="getEasterDay" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getEasterDayResult" name="output" type="text" size="30" readonly="readonly" />
Date.getEasterMonth()   <input id="getEasterMonth" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getEasterMonthResult" name="output" type="text" size="30" readonly="readonly" />
Date.getGMTOffset()   <input id="getGMTOffset" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getGMTOffsetResult" name="output" type="text" size="30" readonly="readonly" />
Date.getLong12Hours()   <input id="getLong12Hours" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getLong12HoursResult" name="output" type="text" size="30" readonly="readonly" />
Date.getLong24Hours()   <input id="getLong24Hours" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getLong24HoursResult" name="output" type="text" size="30" readonly="readonly" />
Date.getLongDate()   <input id="getLongDate" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getLongDateResult" name="output" type="text" size="30" readonly="readonly" />
Date.getLongDayName()   <input id="getLongDayName" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getLongDayNameResult" name="output" type="text" size="30" readonly="readonly" />
Date.getLongMinutes()   <input id="getLongMinutes" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getLongMinutesResult" name="output" type="text" size="30" readonly="readonly" />
Date.getLongMonth()   <input id="getLongMonth" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getLongMonthResult" name="output" type="text" size="30" readonly="readonly" />
Date.getLongMonthName()   <input id="getLongMonthName" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getLongMonthNameResult" name="output" type="text" size="30" readonly="readonly" />
Date.getLongSeconds()   <input id="getLongSeconds" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getLongSecondsResult" name="output" type="text" size="30" readonly="readonly" />
Date.getMeridiem()   <input id="getMeridiem" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getMeridiemResult" name="output" type="text" size="30" readonly="readonly" />
Date.getOrdinalSuffix()   <input id="getOrdinalSuffix" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getOrdinalSuffixResult" name="output" type="text" size="30" readonly="readonly" />
Date.getRFC822Date()   <input id="getRFC822Date" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getRFC822DateResult" name="output" type="text" size="30" readonly="readonly" />
Date.getShort12Hours()   <input id="getShort12Hours" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getShort12HoursResult" name="output" type="text" size="30" readonly="readonly" />
Date.getShort24Hours()   <input id="getShort24Hours" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getShort24HoursResult" name="output" type="text" size="30" readonly="readonly" />
Date.getShortDayName()   <input id="getShortDayName" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getShortDayNameResult" name="output" type="text" size="30" readonly="readonly" />
Date.getShortMonth()   <input id="getShortMonth" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getShortMonthResult" name="output" type="text" size="30" readonly="readonly" />
Date.getShortMonthName()   <input id="getShortMonthName" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getShortMonthNameResult" name="output" type="text" size="30" readonly="readonly" />
Date.getShortYear()   <input id="getShortYear" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getShortYearResult" name="output" type="text" size="30" readonly="readonly" />
Date.getSwatchTime()   <input id="getSwatchTime" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getSwatchTimeResult" name="output" type="text" size="30" readonly="readonly" />
Date.getTimeSeconds()   <input id="getTimeSeconds" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getTimeSecondsResult" name="output" type="text" size="30" readonly="readonly" />
Date.getTimezone()   <input id="getTimezone" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getTimezoneResult" name="output" type="text" size="30" readonly="readonly" />
Date.getTimezoneOffsetSeconds()   <input id="getTimezoneOffsetSeconds" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getTimezoneOffsetSecondsResult" name="output" type="text" size="30" readonly="readonly" />
Date.getWeekOfYear()   <input id="getWeekOfYear" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getWeekOfYearResult" name="output" type="text" size="30" readonly="readonly" />
Date.getZodiacSign()   <input id="getZodiacSign" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="getZodiacSignResult" name="output" type="text" size="30" readonly="readonly" />
Date.isDaylightSavingsTime()   <input id="isDaylightSavingsTime" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="isDaylightSavingsTimeResult" name="output" type="text" size="30" readonly="readonly" />
Date.isLeapYear()   <input id="isLeapYear" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="isLeapYearResult" name="output" type="text" size="30" readonly="readonly" />
Date.isWeekday()   <input id="isWeekday" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="isWeekdayResult" name="output" type="text" size="30" readonly="readonly" />
Date.isWeekend()   <input id="isWeekend" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, "oDate")" /> <input id="isWeekendResult" name="output" type="text" size="30" readonly="readonly" />
   </body>

</html>


      </source>
   
  


Display current date: year, month day in number

   <source lang="html4strict">

<html> <head> </head> <body> <script>

   var mydate=new Date()
   var year=mydate.getYear()
   
   if (year < 1000)
       year+=1900
   
   var day=mydate.getDay()
   var month=mydate.getMonth()+1
   
   if (month<10)
       month="0"+month
   
   var daym=mydate.getDate()
   if (daym<10)
       daym="0"+daym
   
   document.write(year+"/"+month+"/"+daym)

</script> </body> </html>


      </source>
   
  


Display date: day month year in string

   <source lang="html4strict">

<html> <head></head> <body> <script>

   var mydate=new Date()
   var year=mydate.getYear()
   
   if (year < 1000)
       year+=1900
   
   var day=mydate.getDay()
   var month=mydate.getMonth()
   var daym=mydate.getDate()
   
   if (daym<10)
       daym="0"+daym
       
   var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday",
                           "Friday","Saturday")
   var montharray=new Array("January","February","March","April","May","June",
                           "July","August","September","October","November","December")
   
   document.write(dayarray[day]+", "+montharray[month]+" "+daym+", "+year)

</script> </body> </html>


      </source>
   
  


Display full date : complete date with the day name and month name

   <source lang="html4strict">

<html> <body> <script type="text/javascript">

   var d=new Date()
   var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday",
                   "Friday","Saturday")
   var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug",
                   "Sep","Oct","Nov","Dec")
   document.write(weekday[d.getDay()] + " ")
   document.write(d.getDate() + ". ")
   document.write(monthname[d.getMonth()] + " ")
   document.write(d.getFullYear())

</script> </body> </html>


      </source>
   
  


Display time: continues writing time per second.

   <source lang="html4strict">

<html> <head> <script type="text/javascript"> var timer = null function start(){

   var time = new Date()
   var hours = time.getHours()
   var minutes = time.getMinutes()
   minutes=((minutes < 10) ? "0" : "") + minutes
   var seconds = time.getSeconds()
   seconds=((seconds < 10) ? "0" : "") + seconds
   var clock = hours + ":" + minutes + ":" + seconds
   document.forms[0].display.value = clock
   timer = setTimeout("start()",1000)

} </script> </head> <body onload="start()"> <form> <input type="text" name="display" size="20"> </form> </body> </html>

      </source>
   
  


Display weekday: name of the current day

   <source lang="html4strict">

/* Sunday=0, Monday=1 ... */

<html> <body> <script type="text/javascript">

   var d=new Date()
   var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday",
               "Friday","Saturday")
   document.write("Today is " + weekday[d.getDay()])

</script> </body> </html>

      </source>
   
  


Extending the Date Object to Include Some New Methods

   <source lang="html4strict">

<html> <body> <script type="text/javascript" language="JavaScript1.1">

</script> <body> </html>

      </source>
   
  


Get how many days before a date

   <source lang="html4strict">


function getDaysBefore(year, month, date) {

   var oneMinute = 60 * 1000;
   var oneHour = oneMinute * 60;
   var oneDay = oneHour * 24;
   var today = new Date();
   var targetDate = new Date();
   targetDate.setYear(year);
   targetDate.setMonth(month);
   targetDate.setDate(date);
   alert(targetDate);
   var diff = targetDate.getTime() - today.getTime();
   diff = Math.floor(diff/oneDay);
   return diff;

}


      </source>
   
  


GMT Calculator

   <source lang="html4strict">
<html>

<head> <title>GMT Calculator</title> <script type="text/javascript"> function calcGMT(form) {

   var date = new Date(form.year.value, form.month.value, form.date.value, 
                        form.hour.value, form.minute.value, form.second.value);
   form.output.value = date.toUTCString();

} </script> </head> <body> <form> Enter a local date/time
Year:<input type="text" name="year" value="0000">
Month (0-11):<input type="text" name="month" value="0">
Date (1-31):<input type="text" name="date" value="0">
Hour (0-23):<input type="text" name="hour" value="0">
Minute (0-59):<input type="text" name="minute" value="0">
Second (0-59):<input type="text" name="second" value="0">
<input type="button" value="Get GMT" onclick="calcGMT(this.form)">
GMT: <input type="text" name="output" size="60"> </body> </html>


      </source>
   
  


how many days Between two dates

   <source lang="html4strict">


function daysBetween(date1, date2) {

   var DSTAdjust = 0;
   // constants used for our calculations below
   oneMinute = 1000 * 60;
   var oneDay = oneMinute * 60 * 24;
   // equalize times in case date objects have them
   date1.setHours(0);
   date1.setMinutes(0);
   date1.setSeconds(0);
   date2.setHours(0);
   date2.setMinutes(0);
   date2.setSeconds(0);
   // take care of spans across Daylight Saving Time changes
   if (date2 > date1) {
       DSTAdjust = 
           (date2.getTimezoneOffset() - date1.getTimezoneOffset()) * oneMinute;
   } else {
       DSTAdjust = 
           (date1.getTimezoneOffset() - date2.getTimezoneOffset()) * oneMinute;    
   }
   var diff = Math.abs(date2.getTime() - date1.getTime()) - DSTAdjust;
   return Math.ceil(diff/oneDay);

}

var projectLength = 0; // validate form entries with checkDate() function from Recipe 2.12 var startField = document.entryForm.startDate; var endField = document.entryForm.endDate; if (checkDate(startField) && checkDate(endField)) {

   var startDate = new Date(startField.value);
   var endDate = new Date(endField.value);
   projectLength = daysBetween(startDate, endDate);

} if (projectLength > 0) {

   alert("You\"ve specified " + projectLength + " days for this project.");

}


      </source>
   
  


How Many Days Until Christmas

   <source lang="html4strict">

/* JavaScript Bible, Fourth Edition by Danny Goodman John Wiley & Sons CopyRight 2001

  • /

<HTML> <HEAD> <TITLE>Christmas Countdown</TITLE> <SCRIPT LANGUAGE="JavaScript"> function getDaysUntilXmas() {

   var oneMinute = 60 * 1000
   var oneHour = oneMinute * 60
   var oneDay = oneHour * 24
   var today = new Date()
   var nextXmas = new Date()
   nextXmas.setMonth(11)
   nextXmas.setDate(25)
   if (today.getMonth() == 11 && today.getDate() > 25) {
       nextXmas.setFullYear(nextXmas.getFullYear() + 1)
   }
   var diff = nextXmas.getTime() - today.getTime()
   diff = Math.floor(diff/oneDay)
   return diff

} </SCRIPT> </HEAD> <BODY>

<SCRIPT LANGUAGE="JavaScript"> var header = "You have " + getDaysUntilXmas() + " " header += "shopping days until Christmas." document.write(header) </SCRIPT>


</BODY> </HTML>


      </source>
   
  


Methods and Properties of the Date Object

   <source lang="html4strict">

Method getDate() Returns the date within month (1 to 31). getDay() Returns the day within the week (0 to 6). getFullYear() Returns the year in local time with four digits. getHours() Returns the hour within the day (0 to 23). getMilliseconds() Returns the milliseconds. getMinutes() Returns the minutes within the hour (0 to 59). getMonth() Returns the month within the year (0 to 11). getSeconds() Returns seconds within the minute (0 to 59). getTime() Returns the number of milliseconds since 1/1/70 00:00:00. getTimeZoneOffset() Returns minutes offset from GMT/UTC. getUTCDate() Returns the day of the month. getUTCDay() Returns the day of the week converted to universal time. getUTCFullYear() Returns a four-digit representation of the year converted to universal time. getUTCHours() Returns the hour converted to universal time. getUTCMilliseconds()Returns the milliseconds converted to universal time. getUTCMinutes() Returns the minutes converted to universal time. getUTCMonth() Returns the month converted to universal time. getUTCSeconds() Returns the seconds converted to universal time. getYear() Returns number of years since 1900. parse() Converts the passed-in string date to milliseconds. setDate() Sets the date within the month (1 to 31). setFullYear() Sets the year as a four-digit number. setHours() Sets hour within day (0 to 23). setMilliseconds() Sets the milliseconds. setMinutes() Sets the minutes within the hour (0 to 59). setMonth() Sets the month within the year (0 to 11). setSeconds() Sets the seconds within the minute (0 to 59). setTime() Sets the number of milliseconds since 1/1/70 00:00:00. setUTCdate() Sets the day of the month in universal time. setUTCFullYear() Sets the year as a four-digit number in universal time. setUTCHours() Sets the hour in universal time. setUTCMilliseconds() Sets the milliseconds in universal time. setUTCMinutes() Sets the minutes in universal time. setUTCMonth() Sets the month in universal time. setUTCSeconds() Sets the seconds in universal time. setYear() Sets the number of years since 1900. toGMTString() Returns the date string in universal format. toLocalString() Returns the date string in the local system"s format. toSource() Returns the source of the Date object. toString() Returns the date and time as a string in local time. toUTCString() Returns the data and time as a string in universal time (UTC). UTC() Convertscomma-delimited values to milliseconds of UTC date. valueOf() Returns the equivalence of the Date object in milliseconds. Property prototype Property that allows you to add methods and properties to the Date object.

      </source>
   
  


Output day

   <source lang="html4strict">

<HTML> <HEAD> </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript"></SCRIPT> </body> </HTML>

      </source>
   
  


Set date: setDate, setHour

   <source lang="html4strict">

<html> <body> <script type="text/javascript">

   var d = new Date()
   
   d.setFullYear("2005")
   document.write(d)

</script> </body> </html>


      </source>
   
  


Simple Date Validation

   <source lang="html4strict">

/* JavaScript Bible, Fourth Edition by Danny Goodman John Wiley & Sons CopyRight 2001

  • /

<HTML> <HEAD> <TITLE>Simple Date Validation</TITLE> <SCRIPT LANGUAGE="JavaScript"> function validDate(fld) {

   var testMo, testDay, testYr, inpMo, inpDay, inpYr, msg
   var inp = fld.value
   status = ""
   // attempt to create date object from input data
   var testDate = new Date(inp)
   // extract pieces from date object
   testMo = testDate.getMonth() + 1
   testDay = testDate.getDate()
   testYr = testDate.getFullYear()
   // extract components of input data
   inpMo = parseInt(inp.substring(0, inp.indexOf("/")), 10)
   inpDay = parseInt(inp.substring((inp.indexOf("/") + 1), inp.lastIndexOf("/")), 10)
   inpYr = parseInt(inp.substring((inp.lastIndexOf("/") + 1), inp.length), 10)
   // make sure parseInt() succeeded on input components
   if (isNaN(inpMo) || isNaN(inpDay) || isNaN(inpYr)) {
       msg = "There is some problem with your date entry."
   }
   // make sure conversion to date object succeeded
   if (isNaN(testMo) || isNaN(testDay) || isNaN(testYr)) {
       msg = "Couldn"t convert your entry to a valid date. Try again."
   }
   // make sure values match
   if (testMo != inpMo || testDay != inpDay || testYr != inpYr) {
       msg = "Check the range of your date value."
   }
   if (msg) {
       // there"s a message, so something failed
       alert(msg)
       // work around IE timing problem with alert by
       // invoking a focus/select function through setTimeout();
       // must pass along reference of fld (as string)
       setTimeout("doSelection(document.forms["" + 
       fld.form.name + ""].elements["" + fld.name + ""])", 0)
       return false
   } else {
       // everything"s OK; if browser supports new date method,
       // show just date string in status bar
       status = (testDate.toLocaleDateString) ? testDate.toLocaleDateString() : 
           "Date OK"
       return true
   }

} // separate function to accommodate IE timing problem function doSelection(fld) {

   fld.focus()
   fld.select()

} </SCRIPT> </HEAD> <BODY>

Simple Date Validation


<FORM NAME="entryForm" onSubmit="return false"> Enter any date (mm/dd/yyyy): <INPUT TYPE="text" NAME="startDate"

   onChange="validDate(this)">

</FORM> </BODY> </HTML>


      </source>
   
  


Summer Games Countdown

   <source lang="html4strict">

/* JavaScript Bible, Fourth Edition by Danny Goodman John Wiley & Sons CopyRight 2001

  • /

<HTML> <HEAD> <TITLE>Summer Games Countdown</TITLE> <SCRIPT LANGUAGE="JavaScript"> // globals -- calculate only once // set target date to 1700GMT on August 13, 2004 var targetDate = Date.UTC(2010, 7, 13, 17, 0, 0, 0) var oneMinute = 60 * 1000 var oneHour = oneMinute * 60 var oneDay = oneHour * 24 function getTimeUntil(targetMS) {

   var today = new Date()
   var diff = targetMS - today.valueOf()
   return Math.floor(diff)

} function getCountDown() {

   var ms = getTimeUntil(targetDate)
   var output = ""
   var days, hrs, mins, secs
   if (ms >= 0) {
       days = Math.floor(ms/oneDay)
       ms -= oneDay * days
       hrs = Math.floor(ms/oneHour)
       ms -= oneHour * hrs
       mins = Math.floor(ms/oneMinute)
       ms -= oneMinute * mins
       secs = Math.floor(ms/1000)
       output += days + " Days, " + 
                 hrs + " Hours, " +
                 mins + " Minutes, " +
                 secs + " Seconds"
   } else {
       output += "The time has passed."
   }
   return output

} function updateCountDown() {

   document.forms[0].timer.value = getCountDown()
   setTimeout("updateCountDown()", 1000)

} </SCRIPT> </HEAD> <BODY onLoad="updateCountDown()">

Athens Games Torch Lighting Countdown

<SCRIPT LANGUAGE="JavaScript"> if (navigator.userAgent.indexOf("Win") >= 0) { document.write("(" + (new Date(targetDate)).toLocaleString()) document.write(" in your time zone.)") } </SCRIPT>

<FORM> <INPUT TYPE="text" NAME="timer" SIZE=60> </FORM>


</BODY> </HTML>


      </source>
   
  


Today"s Date

   <source lang="html4strict">

/* Examples From JavaScript: The Definitive Guide, Fourth Edition Legal matters: these files were created by David Flanagan, and are Copyright (c) 2001 by David Flanagan. You may use, study, modify, and distribute them for any purpose. Please note that these examples are provided "as-is" and come with no warranty of any kind. David Flanagan

  • /

<html> <head> <title>Today"s Date</title>

   <script language="JavaScript">
   // Define a function for use later on.
   function print_todays_date() {
       var d = new Date();                  // Get today"s date and time
       document.write(d.toLocaleString());  // Insert it into the document
   }
   </script>

</head> <body> The date and time are:
<script language="JavaScript">

 // Now call the function we defined above.
 print_todays_date();

</script> </body> </html>


      </source>
   
  


Using the Date Object

   <source lang="html4strict">

<HTML> <HEAD> <TITLE>Using the Date Object Type</TITLE> </HEAD> <BODY>

Using the Date Object Type

<SCRIPT LANGUAGE="JavaScript"></SCRIPT> </BODY> </HTML>

      </source>
   
  


UTC time: getUTCDate returns the Universal Coordinated Time

   <source lang="html4strict">

/* the time set by the World Time Standard.*/ <html> <body> <script type="text/javascript">

   var d = new Date()
   
   document.write(d.getUTCHours())
   document.write(".")
   document.write(d.getUTCMinutes())
   document.write(".")
   document.write(d.getUTCSeconds())

</script> </body> </html>

      </source>