[] a native js object for working with Date values, see REF 1 and 2 for some basic examples of usage
[] this article shows how to add some additional properties to the native js Date object.
[why]
[] consistency -
[] calculations -
[where]
[] money.js - implements the following example of adding additional properties (monthName, ISODate, ...) to the native js Date object and demonstrates their usage.
[example]
[] adding a new property (monthName) to the native Date object ( using the Date.prototype) ?property?
[] adding a new property (I
[how-to example-1]
// using the "prototype" ___ (property of the Date object) , i am adding a new function/method named "getMonthName()" to the native/primitive js object Date, this method will determine the monthName of the current Date and add/set a monthName property to the Date object
Date.prototype.getMonthName=function() { if (this.getMonth()==0){this.monthName="January"}; if (this.getMonth()==1){this.monthName="February"};
// ... REPLACED the above code with an array of "monthNames" and single statement this.monthName = monthNames(this.getMonth())
}
CALL your new method on the instance of Date that you are working with, to set the value of your new property.
var myDate = new Date();
myDate.getMonthName();
ACCESS the value of the new property that you have added anywhere in your js code
myDate.monthName
[how-to - example-2]
// using the "prototype" ___ (property of the Date object) , i am adding a new function/method named "getISO()" to the native/primitive js object Date, this method will determine the monthNumber of the current Date and set an ISODate format property ( YES i know there is a native js method for this, BUT it doesnt appear to work in all browsers(IE8))
Date.prototype.getISO=function()
// created an array of "monthNumbers"
// used getFullYear().toString and this.getDate() to set Year and Day values
SET this.ISO_8601 property = year+monthNumbers(this.getMonth())+day
}
CALL your new method on the instance of Date that you are working with, to set the value of your new property.
var date = new Date();
date.getISO();
ACCESS the value of the new property that you have added anywhere in your js code