How does Javascript determine whether it is a running year? It is more convenient and simpler to use error correction. The month in the new Date (year, month, day) below starts from 0, and 2 means March, which means constructing March 1 The day before the day, and then check whether the date of this day is 29. In fact, the date object's own error correction calculation is used.
Javascript test function isSmoothYear()
Here is a quote:
1 <script language="javascript">
2 var isSmoothYear = function(year)
3 {
4 return (new Date(year, 2, 0).getDate() == 29);
5}
6 alert("Is 2004 a good year? t" + isSmoothYear(2004));
7 alert("Is 2005 a good year? t" + isSmoothYear(2005));
8 alert("Is 2006 a good year? t" + isSmoothYear(2006));
9 alert("Is 2007 a good year? t" + isSmoothYear(2007));
10 alert("Is 2008 a good year? t" + isSmoothYear(2008));
11 </script>
Java code is similar.
The following is a reference fragment:
1 import java.util.*;
2
3 class TestDate
4 {
5 public static void main(String[] args)
6 {
7 Date date = new Date(2004, 2, 0);
8 System.out.println(date.getDate());
9}
10}
11