File last modified date wrong

Discussion in 'Java' started by Marc Mendez, Aug 21, 2007.

  1. Marc Mendez

    Marc Mendez Guest

    Hi,

    Under W2003 (and once under XP Pro), I can't get the right last modified
    date of a file.

    I use :
    long lastmodified = file.lastModified();
    long currentTime = new GregorianCalendar().getTimeInMillis();

    to know how long a file was changed.

    To trace the routine, I do :

    log.println("Last modified date : " + lastmodified);
    GregorianCalendar t = new GregorianCalendar();
    t.setTimeInMillis(lastmodified);
    log.println("Last modified date (readable) :
    "+t.get(Calendar.DAY_OF_MONTH)+"/"+t.get(Calendar.MONTH)+"/"+t.get(Calendar.YEAR));
    log.println("Current date : " + currentTime);

    A file modified on 16/07/2007 looks modified on le
    16/06/2007 ! I use JRE 1.4.2. On my home computer (XP Pro), no problem.

    Any idea ?
    Marc Mendez, Aug 21, 2007
    #1
    1. Advertising

  2. On Tue, 21 Aug 2007 10:20:42 +0200, Marc Mendez wrote:
    > A file modified on 16/07/2007 looks modified on le 16/06/2007 ! I
    > use JRE 1.4.2.


    The months are numbered starting from 0, so 6 is July, not June.

    > On my home computer (XP Pro), no problem.


    Can't explain that.

    /gordon

    --
    Gordon Beaton, Aug 21, 2007
    #2
    1. Advertising

  3. Marc Mendez

    Marc Mendez Guest

    Yes you're right. But if so, it should occur on any system. Some systems
    give me the right month, the other the wrong one...


    Gordon Beaton wrote:
    > On Tue, 21 Aug 2007 10:20:42 +0200, Marc Mendez wrote:
    >> A file modified on 16/07/2007 looks modified on le 16/06/2007 ! I
    >> use JRE 1.4.2.

    >
    > The months are numbered starting from 0, so 6 is July, not June.
    >
    >> On my home computer (XP Pro), no problem.

    >
    > Can't explain that.
    >
    > /gordon
    Marc Mendez, Aug 21, 2007
    #3
  4. Marc Mendez

    Roedy Green Guest

    On Tue, 21 Aug 2007 10:20:42 +0200, "Marc Mendez"
    <> wrote, quoted or indirectly quoted
    someone who said :

    >long lastmodified = file.lastModified();
    >long currentTime = new GregorianCalendar().getTimeInMillis();


    I would do it like this:

    long currentTime = System..currentTimeMillis();

    long filetime = file.lastModified();

    static final SimpleDateFormat sdf =
    new SimpleDateFormat( "EEEE yyyy/MM/dd hh:mm:ss aa zz :
    zzzzzz" );

    String dateString = sdf.format( new Date( filetime ) );

    This way you see the time zone being used. Most often problems with
    date/time are displaying in a different time zone, DST than you
    thought you were.

    Also check how both machines are configured in the OS.
    See http://mindprod.com/applet/tz.html

    see http://mindprod.com/jgloss/timezone.html
    http://mindprod.com/jgloss/calendar.html
    http://mindprod.com/jgloss/time.html
    http://mindprod.com/jgloss/timestamp.html
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Aug 21, 2007
    #4
  5. Marc Mendez

    Marc Mendez Guest

    That's a good idea, but a different TMZ can give a difference up to one day,
    not a month ;)

    Roedy Green wrote:
    > On Tue, 21 Aug 2007 10:20:42 +0200, "Marc Mendez"
    > <> wrote, quoted or indirectly quoted
    > someone who said :
    >
    >> long lastmodified = file.lastModified();
    >> long currentTime = new GregorianCalendar().getTimeInMillis();

    >
    > I would do it like this:
    >
    > long currentTime = System..currentTimeMillis();
    >
    > long filetime = file.lastModified();
    >
    > static final SimpleDateFormat sdf =
    > new SimpleDateFormat( "EEEE yyyy/MM/dd hh:mm:ss aa zz :
    > zzzzzz" );
    >
    > String dateString = sdf.format( new Date( filetime ) );
    >
    > This way you see the time zone being used. Most often problems with
    > date/time are displaying in a different time zone, DST than you
    > thought you were.
    >
    > Also check how both machines are configured in the OS.
    > See http://mindprod.com/applet/tz.html
    >
    > see http://mindprod.com/jgloss/timezone.html
    > http://mindprod.com/jgloss/calendar.html
    > http://mindprod.com/jgloss/time.html
    > http://mindprod.com/jgloss/timestamp.html
    Marc Mendez, Aug 21, 2007
    #5
  6. Marc Mendez

    Roedy Green Guest

    On Tue, 21 Aug 2007 20:23:40 +0200, "Marc Mendez"
    <> wrote, quoted or indirectly quoted
    someone who said :

    >That's a good idea, but a different TMZ can give a difference up to one day,
    >not a month ;)


    That was not obvious to me . I did not know if you meant DDMMYYYYY or
    MMDDYYYY.

    I use ISO format YYYY-MM-DD since it is unambiguous.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Aug 22, 2007
    #6
  7. Marc Mendez

    Roedy Green Guest

    On Tue, 21 Aug 2007 10:20:42 +0200, "Marc Mendez"
    <> wrote, quoted or indirectly quoted
    someone who said :

    >Under W2003 (and once under XP Pro), I can't get the right last modified
    >date of a file.


    I presume you are not showing us the exact code. Could some sort of
    exception leave the lastModified set to an old value?
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Aug 22, 2007
    #7
  8. Marc Mendez

    Marc Mendez Guest

    No, it was exactly the code. About the TMZ, it's DD/MM/YYYY.

    Roedy Green wrote:
    > On Tue, 21 Aug 2007 10:20:42 +0200, "Marc Mendez"
    > <> wrote, quoted or indirectly quoted
    > someone who said :
    >
    >> Under W2003 (and once under XP Pro), I can't get the right last
    >> modified date of a file.

    >
    > I presume you are not showing us the exact code. Could some sort of
    > exception leave the lastModified set to an old value?
    Marc Mendez, Aug 22, 2007
    #8
  9. Marc Mendez

    Roedy Green Guest

    Roedy Green, Aug 23, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rich Pasco
    Replies:
    2
    Views:
    19,312
    Rich Pasco
    Oct 9, 2003
  2. Roedy Green

    Date last Accessed vs Date Modified

    Roedy Green, Feb 21, 2008, in forum: Java
    Replies:
    1
    Views:
    1,455
    Nigel Wade
    Feb 22, 2008
  3. Elliot
    Replies:
    1
    Views:
    312
    siccolo
    Feb 27, 2008
  4. Elliot
    Replies:
    3
    Views:
    358
    Elliot
    Jun 16, 2008
  5. Boniface Frederic

    last modified date of a text file.

    Boniface Frederic, Jul 13, 2004, in forum: Javascript
    Replies:
    5
    Views:
    105
    Erwin Moller
    Jul 16, 2004
Loading...

Share This Page