Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

File last modified date wrong

Thread view: 
Marc Mendez - 21 Aug 2007 09:20 GMT
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 ?
Gordon Beaton - 21 Aug 2007 09:34 GMT
> 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 - 21 Aug 2007 10:04 GMT
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...

>> A file modified on 16/07/2007 looks modified on le 16/06/2007 ! I
>> use JRE 1.4.2.
[quoted text clipped - 6 lines]
>
> /gordon
Roedy Green - 21 Aug 2007 11:34 GMT
On Tue, 21 Aug 2007 10:20:42 +0200, "Marc Mendez"
<marc.mendez_SPAM_NO@bigfoot.com> 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
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Marc Mendez - 21 Aug 2007 19:23 GMT
That's a good idea, but a different TMZ can give a difference up to one day,
not a month ;)

> On Tue, 21 Aug 2007 10:20:42 +0200, "Marc Mendez"
> <marc.mendez_SPAM_NO@bigfoot.com> wrote, quoted or indirectly quoted
[quoted text clipped - 26 lines]
> http://mindprod.com/jgloss/time.html
> http://mindprod.com/jgloss/timestamp.html
Roedy Green - 22 Aug 2007 04:54 GMT
On Tue, 21 Aug 2007 20:23:40 +0200, "Marc Mendez"
<marc.mendez_SPAM_NO@bigfoot.com> 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.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 22 Aug 2007 05:05 GMT
On Tue, 21 Aug 2007 10:20:42 +0200, "Marc Mendez"
<marc.mendez_SPAM_NO@bigfoot.com> 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?
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Marc Mendez - 22 Aug 2007 15:59 GMT
No, it was exactly the code. About the TMZ, it's DD/MM/YYYY.

> On Tue, 21 Aug 2007 10:20:42 +0200, "Marc Mendez"
> <marc.mendez_SPAM_NO@bigfoot.com> wrote, quoted or indirectly quoted
[quoted text clipped - 5 lines]
> 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 - 23 Aug 2007 01:53 GMT
To get one possible source of confusion out the way, use SetClock to
set your time and let you know the timezone you have configured on the
various machines.

See http://mindprod.com/webstarts/setclock.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.