• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Swing Time

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.....
 
Saloon Keeper
Posts: 15524
364
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic