Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > File last modified date wrong

Reply
Thread Tools

File last modified date wrong

 
 
Marc Mendez
Guest
Posts: n/a
 
      08-21-2007
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 ?


 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      08-21-2007
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

--
 
Reply With Quote
 
 
 
 
Marc Mendez
Guest
Posts: n/a
 
      08-21-2007
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



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-21-2007
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
 
Reply With Quote
 
Marc Mendez
Guest
Posts: n/a
 
      08-21-2007
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



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-22-2007
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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-22-2007
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
 
Reply With Quote
 
Marc Mendez
Guest
Posts: n/a
 
      08-22-2007
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?



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-23-2007
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
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the last modified date of a xml file that on the Internet instead of knowing its content Elliot ASP .Net 3 06-16-2008 05:28 PM
Is it possible to get the last modified date of a rss file without knowing its content using C#? Elliot ASP .Net 1 02-27-2008 01:36 PM
Date last Accessed vs Date Modified Roedy Green Java 1 02-22-2008 09:41 AM
last modified date of a text file. Boniface Frederic Javascript 5 07-16-2004 08:14 AM
How does a perl script get the last-modified date of a file? Rich Pasco Perl 2 10-09-2003 07:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57