We are about to switch to a new forum software. Until then we have removed the registration on this forum.
On my PC the milliseconds value displayed by this code only updates every 2 or 3 minutes, and not continuously. Any suggestions as to why? Thanks, Andrew
import java.lang.System;
void setup() {
size(400, 200);
}
void draw() {
background(255);
fill(0);
text(System.currentTimeMillis(),20,40);
}
Answers
The easiest option would be to use Processing's built in method millis(). But if you have to use native Java for some reason, this should answer your question:
In other words, System.currentTimeMillis() is used for precise dates and hours but is refreshed less frequently (the rate of this refresh depends on the OS).
System.nanoTime() is good for elapsed times for but it is more CPU intensive.
Source: https://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks
Hmm... My answer might be off the track as this is what the implementation of millis() looks like:
println(System.currentTimeMillis()); works properly so it points to a wrong dynamic type casting from long to String.
Let's try this:
Bingo!
Processing isn't fond for all of the 8 Java's primitive types! Data-types byte, short, long & double aren't integrated well! :-O
Main 1s are int & float. While boolean & char are also tolerable by it. 8-|
Yes. Bingo! Not sure I understand the explanation... something about data type conflicts between java and processing ... but thanks guys!
Hi Andrew.
I'm glad it was helpful. Please accept an answer so this thread gets cleared from the "unanswered" list.
Have a nice day :)