How to print time ellapsed (seconds)java -
in run method of game loop tried print time program has been running in java. tried system.out.println(system.nanotime() / 1000000);
because that's how many milliseconds in second.(if didn't know) prints seconds near end wanted exact seconds testing purposes. searched online , suggested using same formula thought of. can give exact one?
store previous time in private member.
private long previoustime;
initialize in constructor.
previoustime = system.currenttimemillis();
compare current time in run method (each iteration of game loop)
long currenttime = system.currenttimemillis(); double elapsedtime = (currenttime - previoustime) / 1000.0; system.out.println("time in seconds : " + elapsedtime); previoustime = currenttime;
Comments
Post a Comment