Hi !
Featured games (87)
games approved by the League of Dukes
Games in Showcase (671)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (727)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to get currentTime from System?  (Read 1272 times)
0 Members and 1 Guest are viewing this topic.
Offline Danskeren

Senior Devvie

Projects: 1


« Posted 2005-01-30 01:53:08 »

I wanna make a game where the speed be a matter of CPU speed so I need to get the currentTime from the SYstem. How do I do that?

Offline Lemon

Senior Newbie

Java games rock!

« Reply #1 - Posted 2005-01-30 05:44:13 »

Use the following System.currentTimeMillis() .
It returns the current time in milliseconds, so a value of 1000 is 1 second.


Offline Karl

Junior Newbie

Java games rock!

« Reply #2 - Posted 2005-01-30 06:15:01 »

Starting with Java 1.5 you could use
long time = System.nanoTime()
to get a 10^-9 seconds resolution which is more accurate than the currentTimeMillis() call.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jackal von ÖRF

Junior Devvie

« Reply #3 - Posted 2005-01-31 05:25:43 »

long time = System.nanoTime()

Would somebody know how accurate is that function? Does it use CPU counters as discussed in this thread?

The API says that "This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change." So what is the accuracy of the implementations on Windows and Linux machines?

Offline Valodim

Junior Devvie


« Reply #4 - Posted 2005-02-02 17:54:58 »

it's the most accurate time you can get for comparison purposes Tongue
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

IanParcs (38 views)
2016-04-18 14:18:53

KaiHH (38 views)
2016-04-18 08:35:41

KaiHH (69 views)
2016-04-15 12:43:58

theagentd (71 views)
2016-04-14 02:16:17

theagentd (82 views)
2016-04-14 02:15:43

IanParcs (96 views)
2016-04-12 03:51:16

IanParcs (39 views)
2016-04-12 03:50:03

IanParcs (35 views)
2016-04-12 03:49:54

IanParcs (32 views)
2016-04-12 03:49:52

IanParcs (40 views)
2016-04-12 03:49:52
Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!