document.lastModified returns current date!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Norvell

    #1

    document.lastModified returns current date!

    I just noticed that recently the javascript I was using to format and
    display the last modified date of my web page is always reporting the
    current date instead. It used to work fine. This is true both on the
    university web server on which the page is hosted and the local mirror I
    keep on my desktop (SuSE 8.2 Linux). It is a new university, but my
    desktop filesystem is the same as before. I can see with "ls -l" that the
    modified date of the file has not been changed. I am really befuddled! I
    have tried several different scripts now, and they all show the same
    behavior. Any clues about this?

    Here's what I've been using:

    // Formatted last-modified date
    if (Date.parse(doc ument.lastModif ied) != 0) {
    var modiDate = new Date(document.l astModified); var modiYear =
    modiDate.getYea r();
    modiYear = (modiYear < 2000) ? modiYear + 1900 : modiYear; var
    monthName = new Array("January" , "February", "March", "April",
    "May",
    "June", "July", "August", "September" , "October", "November",
    "December") ;
    document.write( monthName[modiDate.getMon th()] + " ");
    document.write( modiDate.getDat e() + ", " + modiYear); }
    //

    I call it like this:

    <SCRIPT SRC="datemod.js " LANGUAGE="JavaS cript"></SCRIPT>

    --John
  • Dr John Stockton

    #2
    Re: document.lastMo dified returns current date!

    JRS: In article <pan.2004.01.17 .23.21.59.59425 3@remove-this-nospam-
    part.fas.harvar d.edu>, seen in news:comp.lang. javascript, John Norvell
    <norvell@remo ve-this-nospam-part.fas.harvar d.edu> posted at Sat, 17 Jan
    2004 18:22:00 :-[color=blue]
    >I just noticed that recently the javascript I was using to format and
    >display the last modified date of my web page is always reporting the
    >current date instead. It used to work fine. This is true both on the
    >university web server on which the page is hosted and the local mirror I
    >keep on my desktop (SuSE 8.2 Linux). It is a new university,[/color]

    ?? Even by Oxbridge, Harvard is no longer considered really "new" ??
    [color=blue]
    > but my
    >desktop filesystem is the same as before. I can see with "ls -l" that the
    >modified date of the file has not been changed. I am really befuddled! I
    >have tried several different scripts now, and they all show the same
    >behavior. Any clues about this?[/color]

    Perhaps you meant "the University's server is new"?

    [color=blue]
    >Here's what I've been using:
    >
    >// Formatted last-modified date
    >if (Date.parse(doc ument.lastModif ied) != 0) {
    > var modiDate = new Date(document.l astModified); var modiYear =
    > modiDate.getYea r();
    > modiYear = (modiYear < 2000) ? modiYear + 1900 : modiYear; var
    > monthName = new Array("January" , "February", "March", "April",
    > "May",
    > "June", "July", "August", "September" , "October", "November",
    > "December") ;
    > document.write( monthName[modiDate.getMon th()] + " ");
    > document.write( modiDate.getDat e() + ", " + modiYear); }
    > //[/color]

    Since that gives date-like but unsatisfactory results, look directly at
    lastModified. If that shows "today", you cannot hope to get a desired
    earlier modification date by correcting the code shown.

    If you think your Subject line is an accurate representation of the
    situation, why did you think it necessary to give the code that
    interprets it?


    That code, on a test page dated 2003-12-30, reports "December 30, 1903";
    your Y2k logic is inadequate, but the interpreting code is presumably
    NOT responsible for giving you "today".

    For that page, lastModified shows me 12/30/03 20:20:54, and getYear
    gives 3, in my MSIE 4. Note that, as well as missing 20, the date field
    order is incorrect.


    You should have read the c.l.j FAQ, which gives relevant advice; you
    should read <URL:http://www.merlyn.demo n.co.uk/js-date3.htm#lM>.


    It seems evident that either the server is returning the current date in
    the Last-Modified line of the HTTP header, in which case reconfigure the
    server and/or its operator; or that it is returning no such line, in
    which case the fault is on your machine, in interpreting the absence of
    data unsatisfactoril y.


    Note that L-M is transmitted in GMT & marked as such, or AIUI should be;
    d.lM is likely to use the same figures, without GMT, for at least some
    browsers; Date.parse assumes local time by default. The zone of origin
    is not known, so the author's upload date cannot be known for a WWW
    page. The coder can cause either the GMT date or the reader's date to
    be shown; but should indicate clearly which is the case.

    The only sensible move is for the author to write the date, in an
    internationally unambiguous manner, in the HTML; it should then be
    assumed to be author's local civil date, unless otherwise specified.
    [color=blue]
    >--John[/color]

    FYI:
    A correct SigSep is a line containing only the three characters '-- '.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
    <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

    Comment

    Working...