Print date time

How can I print something like this: 28/11/2016 - 23:56:02

Answers

  • Answer ✓

    Use day(), month(), year(), hour(), minute(), and second().

  • Answer ✓

    println("Today's date is "+day()+"/"+month()+"/"+year);

    Kf

  • But can it stay counting the time? like that: 28/11 - 23:56:02...03...04...

  • can it stay counting the time?

    Do you mean, can one draw text on the sketch screen, rather than to the console?

    text() for the screen, println() for the console:

  • I mean for the screen, like that : https://time.is/PT

  • Yes. Use text(). This is very simple, and any example is a solution. Please attempt it yourself.

  • It will stay counting? According to the seconds that are passing?

  • Yes. Did you read the reference for second()? It looks at your computer's clock. Hopefully your clock keeps counting seconds.

    Keep in mind that you will need to DRAW the text - printing it to the console isn't what you want.

  • edited November 2016 Answer ✓

    @br1mosciatti --

    It will stay counting?

    You aren't understanding how Processing works. In simple sketches, you put things in draw() to draw them.

    Look at the reference for draw() -- draw() is called (by default) 60 times a second. So if you put anything in there, it will "keep going."

    For questions this simple, you should first just try doing it, then ask. When you use text() to put second() on the screen, what happens? Just do it and find out!

    void draw(){
      background(0);
      text(second(),width/2,height/2);
    }
    
  • Thanks, I'm at work now, thats why I didnt try yet. I'll feedback later when got some tests. Thanks

  • Got it! :D

    text(day()+"/"+month()+"/"+year()+" - "+hour()+":"+minute()+":"+second(),width/2,height/2);

Sign In or Register to comment.