27 января 2010

javascript: количество дней в месяце

Самая аскетичная реализация:
 
function daysInMonth(iMonth, iYear) {
  return 32 - new Date(iYear, iMonth, 32).getDate();
}

How does this function work? It is quite simple. When the Date()
function is given a day number that is greater than the number of days
in the given month of the given year, it wraps the date into the next
month. The getDate() function returns the day of the month, starting
from the beginning of the month that the date is in. So, day 32 of
March is considered to be day 1 of April. Subtracting 1 from 32 gives
the correct number of days in March

Комментариев нет:

Архив блога

What to do?

Problem:
you have site designed in a dark theme, saying dark background, white font.
By default google toolbar autocomplete cracks html for inputs or selects containg "email" "name" "address" and other buzzwords and changes background to yellow. As a result when visitor fills form, he enters text as white on yellow and can not easy validate his input
What to do?

Таги

Followers

item http://www.voronenko.com/2010/01/javascript.html