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

Q658 The lastModified doesn't appear to be Y2K compliant, for example a document amended with a date of 11th of June 2001 will show 01 as the year when using either getDate() or getFullDate(), is there a workaround?

You are here: irt.org | FAQ | JavaScript | Date | Q658 [ previous next ]

Try:

<P>Last Modified Date:

<SCRIPT LANGUAGE="JavaScript"><!--
document.write(document.lastModified);
//--></SCRIPT>

<P>Last Modified Date (as a date):

<SCRIPT LANGUAGE="JavaScript"><!--
var lmDate = new Date(document.lastModified);
document.write(lmDate);
//--></SCRIPT>

<P>Last Modified Date using getYear():

<SCRIPT LANGUAGE="JavaScript"><!--
var lmDate = new Date(document.lastModified);
document.write(lmDate.getYear());
//--></SCRIPT>

<P>Last Modified date using getFullYear():

<SCRIPT LANGUAGE="JavaScript"><!--
var lmDate = new Date(document.lastModified);
document.write(lmDate.getFullYear());
//--></SCRIPT>

<P>Last Modified date using getCorrectedYear():

<SCRIPT LANGUAGE="JavaScript"><!--
var lmDate = new Date(document.lastModified);

function getCorrectedYear(year) {
    year = year - 0;
    if (year < 70) return (2000 + year);
    if (year < 1900) return (1900 + year);
    return year;
}

document.write(getCorrectedYear(lmDate.getYear()));
//--></SCRIPT>

©2018 Martin Webb