File last modified date wrong

M

Marc Mendez

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 ?
 
M

Marc Mendez

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...
 
R

Roedy Green

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
 
M

Marc Mendez

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

Roedy Green

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.
 
R

Roedy Green

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top