Java script consist of a Date object which is kind of similar to the Java Date object where as it uses the time since the epoch but some utility method available in the Java language are not available in the JS Date object version. Some of the utility method which i cared to share are as follows;
getDate() - Get the day of month e.g 1-31
getMonth() - Gets the month of the year. Note that it starts with 0-11 So Jan is basically 0.
getFullYear() - Gets the current year as a four digit character
Also we can pass the date as a string literal to the date object as new Date("08/09/2007") which it will convert to the intended date time. It also consists of a toString method which is a bit too cryptic and should not be used when showing specific date objects. The above in-built methods should be used instead to show the user a properly formatted date.
How do you get teh number of days between two days;
This can be done as follows;
//Assuming that date 2 is after date 1
return Math.round( (date2-date1)/(1000*60*60*24));
Wednesday, August 5, 2009
//Sorts values in descending order
var myarray = new Array([1,3,7,10,32,45]);
Behold Method 2!!!!!!! (Drum roll please)
Thats about it for now. But more to come very soon guys. So stay on the look out for all those Java script newbies like myself :).