A simple 0-filling program

Hi!
Isn’t it annoying that the “hour()”, “minute()”, “second()”, … functions output unorganised integers?
(For example, if the time is 21:05:09, than the second() function would return “9” instead of “09”)

Here is a simple program to fix it!

Here is the code:

void setup() {
}

void draw() {
  println("The better way: " + loadZeros(hour(),2) + ":" + loadZeros(minute(),2) + ":" + loadZeros(second(),2));
  println("The normal way: " + hour()+":"+minute()+":"+second());
  println("");
}

String loadZeros(int number, int len) {
  if((number+"").length() < len) {
    String prefix = "";
    for(int i = 0; i < len-(number+"").length(); i++) {
      prefix += "0";
    }
    return(prefix + number);
  } else {
    return(number+"");
  }
}

With this you can also turn any intiger into intigers with length. (input loadZeros(131,5), output=“00131” (in String form).

Feel free to use it in any of your projects!

1 Like

Well… honestly I didn’t know. Looks like it already exists

Is there a way to see the sourcecode of an already existing function?

So this is all the code that runs processing functions? But then why do the processing export files take up 70mb even for a simple clock? (I don’t know much about programming languages)

Edit: Don’t normal Java apps take 1/10 of that?

Processing.GitHub.io/processing-javadocs/core/