Javascript Formatted Date Class

I have written a DateFormatted object for Javascript. I have patterned my code after the Date class in PHP and it can be called much in the same way

If you want to display the current date in a custom format, you can use my library and add three lines of code. First add my javascript file, date.js, to your document:

<script type="text/javascript" src="date.js"></script>

Next, add these two lines of code somewhere in a javascript function.

myDate = new DateFormatted('D, M R, Y');
myDateString = myDate.toString();

That is it! myDateString will now contain the date in the format of your choice.

The class only takes in one argument and produces the current date.

stringFormat ==> There are three parts: day, month, and year. Here are the string characters that represent each:

d ==> day in numbers (1,2,3.....30)
R ==> day in numbers and words (1st,2nd,3rd.....30th)
D ==> day in words (Monday,Tuesday,Wednesday.....)
m ==> month in numbers (1,2,3.....12)
M ==> month in words (January, February, March.....)
y ==> year with two numbers (06)
Y ==> year with four numbers (2006)

Examples of this class after toString() is called would look something like this:

'm-d-Y' ==> '12-20-2006'
'm/d/Y' ==> '12/20/2006'
'D, M R, Y' ==> 'Wednesday, December 20th, 2006'.


(More details of this class are inside the date.js file).