okay to start off, the date object is pretty cool to use. The only thing I don't like, is that it is only as in depth as numbers. If you want to define anything any other way, you need to build an array or two. Which don't get me wrong, this could be very useful, but is very tedious.
Lets get started.
1.Wed Sept 10 00:00:00 PDT 2007
This was easy, basically create a new date and alert it.
var myDate = new Date();
alert(myDate)
you will need the myDate variable to accomplish each question
2.9/15/2007
In order to do this, you need to use a couple methods from the date object.
I used
getMonth
getDate
and getFullYear
Create variables for each of these that distract the value from the entire date.
an ex.
var day = myDate.getDate()
var month = myDate.getMonth();
var year= myDate.getFullYear();
then alert those in a sequence.
document.write(month + "/" + day + "/" + year);
3. February 10, 2007
This question is wak, basically you have to create an array to hold each month.
Then you want to use the index number to pull which month it is from the array.
var monthArray=new Array(12);
//Create an Array to hold all strings of months of year
monthArray[0]="January";
monthArray[1]="Febuary";
monthArray[2]="March";
.....
var m = myDate.getMonth();
document.write(monthArray[m] + " " + day + ", " + year);
To write the string properly you need to build the string using the same concept as the last question
4.Output today’s date in this format: Monday, October 15, 2007
This concept is exactly the same. You need to build an array for the days of the week, and the month. The only trick is to use the getDay method to get the number of the day in the month, rather than the getDate the day of the week. :D
good Luck!
5.Output the time in this format: 11:30:03 AM
Heres another fun fun tedious ass time thing blah!
easy enough though this holds all the exact same concepts as the last ones. Except you use the
getHours
getMinutes
getSeconds methods
also, to be fancy I created a little conditional statement to display the AM or PM
I started out by finding out what that means.
Meridiem its latin! crazy
then i wrote a conditional statement that takes the hour of the day and sees if its before or after 12. noon.
//Define meridiem of day
var meridiem = String;
if(hour <= 11){
meridiem = " AM";
} else {
meridiem = " PM";
}
Then document. write your string. Easy as that
The other questions were over my head. :D
comments comments...
Tuesday, August 19, 2008
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment