Some reader contributions to Calendar tutorial
When I started SZOJ I promised myself I wouldn't abruptly shut down the blog if I lost interest; I'd just go radio silent until my interest was piqued again. That said, it's been a long while. So here are two things:
Rory Parle wrote in to point out you can use Math.ceil to determine the number of rows you'd need to safely render a calendar:
Math.ceil((monthLength + startingDay) / 7);
Michiel van der Blonk suggested a way to determine the number of days in a month:
var d = new Date(nYear, nMonth + 1, 0); // nMonth is 0 thru 11 return(d.getDate());
The mechanism here is the Date constructor will attempt to convert year, month and day values to the nearest valid date. So in the above code, nMonth is incremented to find the following month, and then a Date object is created with zero days. Since this is an invalid date, the Date object defaults to the last valid day of the previous month — which is the month we're interested in to begin with. Then getDate() returns the day (1-31) of that date — voilá, we have the number of days.
Bonus: it also seems to automatically correct for leap year. It feels like a hack but it seems to work consistently.
Thanks to Rory and Michiel for their contributions.
13 Comments:
That's the same trick we Excel nerds have been using to calculate the first day of the next month: =DATE(2007,MONTH(NOW())+1,1)-1
Thanks for the tip. Iv'e been looking to do this for some time.
Dan
Your last tutorial was brilliant! I've had a good go at it and managed to produce what you have. Just trying to work out how to have nifty little next month/previous month buttons now. :)
Thank you!
This comment has been removed by the author.
hello i am having a problem
i am using ajax to load my page i request for html page and get response in html format i want to cut specific data from html xmlHttp.open("GET","http://all-about-ngage.blogspot.com/2006/11/n-gage-games.html",true);
var resp=new String(xmlHttp.responseText);
document.getElementById("postdata").innerHTML = resp.getElementById("pstdata").innerHTML;
i am doing this but it is not working can you tell how to cut HTML between specific tag from the response
Come back!!! lol
:)
Pretty please?
:)
Ai redescoperit roata. Intrepetorul cod al browserului face apel la calendarul intren al procesorului, care corecteaza automat data. Voila.
thank for the tip but i can't see the 1/2 paragrapgh
garminstreetpilot
Very useful tips..
Thanks...
consolidation federal loan
By now, you probably know that magnetic bracelets are used for hand, wrist, arm, and shoulder pain. You may also have heard that golfers and arthritis sufferers wear them, and others wear them as a preventative measure.Sorry out of topic!
http://magnetic-bracelet-clasp.blogspot.com/
Hi
tq very much for ur tips
Cheers,
tandem bicycles
good for the tips
http://laser-hair-removal-for-men.blogspot.com/
Post a Comment
<< Home