The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

HELP "code needed"

Hello

Can someone please show me code in Java that stores the date and time into a file every minute?
The reason for this is that i am looking to copy every minute from the computer clock in order to see if changes have been made.

I am not sure if I need to use a loop of some sort or whether there is code itself that will do this for me.

Re: HELP "code needed"

Welcome to Java Programming Forums Dave.

Well lets see what you have as a starter, so we have a place to build off. A loop will be needed to make it run yes Thread.sleep() may also be helpful in timing, or you could use System timing if you wish to be more accurate.

Re: HELP "code needed"

i do have a couple of extra issues/ help with this

1. will this coinside with the computer. if not how can i make this happen as this is really important

2. i am also looking at adding a method that will not allow you to change the clock by more than 5 mins at a time. This is why i need the recordings to coincide with the computer clock. Also if it is possible i would like to add a rule that will allow the clock to change when the clocks naturally move forward or back (GMT)

finally i am looking to add a password box in order to end the program and also ideally a password box that needs to be typed when i call for the list of times.

I know this sounds like i am throwing alot out there however i am researching to see if java can be used as a computer clock monitor as part of a computer forensics research.

Re: HELP "code needed"

Originally Posted by Dave

i do have a couple of extra issues/ help with this

1. will this coinside with the computer. if not how can i make this happen as this is really important

2. i am also looking at adding a method that will not allow you to change the clock by more than 5 mins at a time. This is why i need the recordings to coincide with the computer clock. Also if it is possible i would like to add a rule that will allow the clock to change when the clocks naturally move forward or back (GMT)

finally i am looking to add a password box in order to end the program and also ideally a password box that needs to be typed when i call for the list of times.

I know this sounds like i am throwing alot out there however i am researching to see if java can be used as a computer clock monitor as part of a computer forensics research.

Once again any help will be appreciated.

Thankyou

Dave

This is a very interresting question. It can probably be pulled of, but it will need some hardcore coding, beyond what java is capable of(if what I understanding from your questions is correct that is.)
Im hoping one the sharp minds will look this over, and either correct me if im wrong, or show some magic.

1. The Calendar gives you the time read of the computer clock, everytime you make a new instance. In other words, change the computer clock, changes the println respectivly.

2. Here is what i understand. You want to "fix" your computer clock, so it cant be modified with more than x on one change. If that is the case, it cant be solved by java, atleast not java alone. Your clock i run in the os.
Java is run in a virtual mashine (jvm), which isolates it from its environment (memory, os etc). Contact in and out of the jvm is tricky at best, impossible at worst. There is a framework(Java Native Interface) specializing in exactly this, but other than knowing how to use it, you also need to have a very good understanding of your os, to manipulate it in a way like this.
In windows you can change pretty much anything if you know how, dont know to much about different linux destros, but im guessing its the same.

3. If by password you mean "cant shut down the program without it" then no, cant be done in java (read 2).

Re: HELP "code needed"

Ye, Java cannot interact with the clock to the level that you wish as stated by Johannes. But he is correct, JNI (Java Native Interface) wil allow you to communicate with C or C++ which can then work nicely with system operations and can do that sort of thing. Again you cannot stop the user from closing the program down as they can get at it from a system level. But once again JNI and C or C++ can be used to deal with this. If you are prepared to learn how to use the JNI and C or C++ if you are not already familiar then you are ok. Ofcourse since you are investigating if Java alone can do it then I have to say no.

Also if you inlist the aid of C or C++ and system functions, you have just lost portability.

Chris,
This reminds me, I have a Mouse/Keyboard hook to finish writing in C++ using JNI D:

Re: HELP "code needed"

Never, never use Thread.Sleep() you will end up totally wrong. It waits more than given time and it can wait lot longer when your processor cycles are sucked by some other process. Look at this as well: Thread (Java 2 Platform SE v1.4.2), int)