JS to get the current year practice is Var dayobj=new Date (); Dayobj.getyear () to get the year, I have written earlier this will appear browser compatibility problem, is in IE can get the results we want but not in FF, and we want the results of 1900 years difference. At the time, my approach was:
var dayobj=new Date ();
var myyears = (Dayobj.getyear () < 1900)? (1900 + dayobj.getyear ()): Dayobj.getyear ();
document.write (Myyears);
This avoids the compatibility problems of IE and ff.
Now I see in JS there is such a method getFullYear (). To test, the original method can avoid the above problems, IE and FF can be as we want to show.
getFullYear method
returns the year value in a Date object that is expressed in local time.
Dateobj.getfullyear ()
The required option Dateobj parameter is a Date object.
Description
To obtain a year value expressed in global standard Time (UTC), use the getUTCFullYear method.
The getFullYear method returns the year value as an absolute number. For example, the return value for 1976 is 1976. This would avoid a 2000 problem and would not confuse the date after January 1, 2000 with the date after January 1, 1900.
The following example illustrates the use of the getFullYear method.
function Datedemo () {
var d, s = "Today UTC date is:";
D = new Date ();
S + + (D.getmonth () + 1) + "/";
S + + d.getdate () + "/";
S + + d.getfullyear ();
return (s);
}