Getting fast format time
in
Programming Questions
•
2 years ago
Hi guys, i made, with some mix of research and "
trial and error",
a relative good and fast formated time to draw an applet;
in this implementation i formated only seconds and milliseconds:
assuming you already do in setup():
Thanks
a relative good and fast formated time to draw an applet;
in this implementation i formated only seconds and milliseconds:
assuming you already do in setup():
- public void setup(){
- loadFont();
- }
- protected void drawSeconds(boolean draw){
- if (draw) {
- text(getFastFormatedTime(), width-(mPFont.getSize()*9), (float) (height-(mPFont.getSize()*0.5)));
- }
- }
- protected String getFastFormatedTime() {
- /* with some crazy calcs... (my cat and this are reference:
- * http://en.wikipedia.org/wiki/Modulo_operation#Performance_issues :P)
- * i found good formating with seconds and milliseconds:
- *
- int t = (millis() & -2)-1;
- String s = String.valueOf(t).substring(0,String.valueOf(t).length()%4+1)+":";
- String ms = String.valueOf(t).substring(String.valueOf(t).length()%4+2,String.valueOf(t).length()%4+4);
- return s+ms;
- }
Thanks
1