Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org

BBS: Re: JavaScript on Y2K - August 21, 1998 at 03:32:51

You are here: irt.org | BBS | Re: JavaScript on Y2K [This BBS is closed]

Posted by Martin Webb on August 21, 1998 at 03:32:51:

In Reply to: Re: JavaScript on Y2K posted by Chan Yen Jet on August 21, 1998 at 00:40:38:

: Actually, what I want is to display current date in dd/mm/yyyy

: Below is the code:
: var today = new Date ()
: var year = today.getYear () + 1900
: ....
: ...
: document.write (year)

: I guess right now there should no problem on my the date, because is will should us 1998 (98+1900), but how about year 2000 ? What will it display after add to 1900?

: What can make sure that the above code will display the correct date and what will be the best solution to this ?

: Thanks.

Check the value of year before adding 1900 to it:

function y2k (number) { return (number < 1000) ? number + 1900 : number; }

var year = y2K (today.getYear ());


Follow-ups:

You are here: irt.org | BBS | Re: JavaScript on Y2K [This BBS is closed]

©2018 Martin Webb