Link to home
Start Free TrialLog in
Avatar of JaZziD
JaZziD

asked on

how to check System Time on different computer with Java?

Hi experts

Basically i have a program that's installed in a computer, it's looking into a directory (could be local or somewhere in the server/different machine) for any new files.

How it works, everytime the program does a scan it will save the time in the config file so then in the next loop it will only check if there is any new file from the last time it scanned.

It doesnt have any problem if the directory is in the same computer. However i just had problem where the directory is in a different computer (a server) and the time is an hour behind, so it will always see new files as old files because of the time difference.

Now the question is:

Is there a way for me to check what's the time oin the other computer from where i installed my program?

Thanks very much
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Next time you scan, all the file with a date > the stored time are new.
Then store max(date of all new files) as the new date for the next scan
You could use a Map

RemoteFileName->RemoteFileDate

Iterate the keys and insert if not present. If present, compare current timestamp with one stored in the Map as its value
Even better - don't write anything at all. What you need is a Java implementation of Unix rsync:

http://jarsync.sourceforge.net/
Avatar of JaZziD
JaZziD

ASKER

CEHJ:
Thanks for the answer
And for the info rsync, i will have a look

zzynx:
originally we wanted to do it that way. The only problem during the installation normally there are already thousands of files in there (which we dont want and cant be deleted either). Therefore during its first run, the program will get the system's current time and will only pick newer files and keep updating "last scan time" after each scan. If we decided to use your method after the program get the system's current time (the first time - we still need to do this) and only uupdate "last scan time" when there's a new file. Then we wont get any files for the first 1 hour (due to the time difference).



Yep that's exactly what rsync is for
>> If we decided to use your method after the program get the system's current time
With my method the program doesn't need to get the system's time.
>> (the first time - we still need to do this)
Why?

At the first scan you browse all files and take the "maximum" of all file times as the time to store for the next scan
Or do I forget something?
Avatar of JaZziD

ASKER

zzyx:
>>Or do I forget something?
no, actually you're right.

I forgot to tell you this, in some clients they had like millions of files in the directory we just decided to ignored all of them straight away, hence just get the current time.

however now that we have this new problem that we didnt think bout, i think your option is better.

Thanks so much for that, i will split the point between you and CEHJ
:-)
Thanks