Re: Javascript for Date Last Changed & Y2K
[ Follow Ups ] [ Post Followup ] [ Intranet eXchange ] [ IDM Home ]
Posted by bill palmer on January 5, 2000 at 3:57:41:
In Reply to: Re: Javascript for Date Last Changed & Y2K posted by Paula Gregorowicz on January 4, 2000 at 15:9:21:
Since various browsers will return either 100, 1900 or 2000 and we always want 2000 it may be best to just make a function like the following(and note use of % operator which gives a remainder after dividing): //the following function only gives a result from 1950 to 2049 function getYear4(aYear){ var vYear=parseInt(aYear); var v1950to2049=0; if (vYear % 100 < 50 ) { v1950to2049=(vYear % 100) + 2000 } else { v1950to2049=(vYear % 100) + 1900 }; return v1950to2049; }; //then using the function var date= new Date(Date.parse("01/01/1900")); document.write=("Year is " + getYear4(date.getYear()) + "" ); Even though getYear is 1900, above writes out: Year is 2000
Follow Ups:
|