This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Swing Time  RSS feed

 
abhinav parankusham
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I have been looking for code to insert clock time into jframe and it should not change when system time is changed...
Can you help me.....
 
Stephan van Hulst
Saloon Keeper
Posts: 7821
142
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what you can do is get System.currentTimeMillis() and System.nanoTime() at the start of your application. Let's call the first one "time" and the second one "start".

If at any point during the execution of your application you want to know the current time, call System.nanoTime() and subtract "start" from it. The result is the amount of nano-seconds since "time". Neither of these values is subject to changing the system clock.

I'm sure you can figure out what to do with those values from there. If you run into troubles, tell us what you have tried and we'll see if we can help you out some more.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since that uses the system time, it appears to me that it will change
when system time is changed...


(No, I'm not about to start playing with my system time setting to confirm that )


Or not. I just read the API more minutely.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!