# Time as float values

**URL:** https://discourse.processing.org/t/time-as-float-values/36327
**Category:** Coding Questions
**Created:** [April 14, 2022, 4:07am UTC](https://discourse.processing.org/t/time-as-float-values/36327 "2022-04-14T04:07:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![arcadeperfect](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@arcadeperfect](https://discourse.processing.org/u/arcadeperfect)
#### Post date: [April 14, 2022, 4:07am UTC](https://discourse.processing.org/t/time-as-float-values/36327/1 "2022-04-14T04:07:10Z")

</div>

hello!

I’m making an ‘analog’ clock, but I want the hands of the clock to move smoothly between values, rather than snapping to the int values returned by hour(), minute(), and second()

I know I could implement something counting elapsed millis and adding them to the current second value to interpolate between one second and the next, and so on.

However I was wondering if there’s a value I can access that represents the time as an absolute value that can be remapped, or a library like dateTime in python that allows you to subtract time objects to get deltas

Thanks!

---

<div class="post-metadata">

### Author: ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)
#### Post date: [April 14, 2022, 4:40am UTC](https://discourse.processing.org/t/time-as-float-values/36327/2 "2022-04-14T04:40:57Z")

</div>

For hour you can use minutes to smooth the movement. Formula `hour() + minute()/60` gives you enough precision for hour hand. Same thing with minutes `minute + second()/60` Second is trickier, but that may be solved with millis(). When second() changes take value of millis() and divide difference with current millis() by 1000.  
Hand for seconds might be a bit jerky, but it’s movement is so short that you probably wont notice it.  
the other option is to set time at start from hour(), minute() and second() and store millis() and then work the change in time from current millis() and stored millis()

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [April 14, 2022, 5:21am UTC](https://discourse.processing.org/t/time-as-float-values/36327/3 "2022-04-14T05:21:40Z")

</div>

Hi  
This may help

> [@Analogue Clock Second hand Sweep not Tick](https://discourse.processing.org/t/analogue-clock-second-hand-sweep-not-tick/2331):
>
> Hi All, I’m busting my brains with this one. I’ve taken the very simple clock sketch from the examples, but instead of drawing the lines I’m using images of clock hands. I currently have my clock working perfectly, however I want the second hand to sweep, not tick. float s = map(second(), 0, 60, 0, 360); The above command is the one i’m using. (s is used in my radians) pushMatrix(); translate(411, 349); rotate(radians(s)); image(secondHand, -16, -190); popMatrix(); Now understanda…

---

<div class="post-metadata">

### Author: ![arcadeperfect](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@arcadeperfect](https://discourse.processing.org/u/arcadeperfect)
#### Post date: [April 14, 2022, 6:45am UTC](https://discourse.processing.org/t/time-as-float-values/36327/4 "2022-04-14T06:45:46Z")

</div>

Here’s what I came up with

Works except there’s a jump after the first second / minute / hour as it doesn’t know how far through a given interval it is when it boots

Should be easy enough to fix for minute and hour, may have to live it with for second

```nohighlight
float m;
float s;

float r = 0;

float offset1 = 0;
float offset2 = 0;

float secondMillis;
float prevSecondMillis;

float minuteMillis;
float prevMinuteMillis;

float hourMillis;
float prevHourMillis;

int prevSecond;
int prevMinute;
int prevHour;

float seed = 0;

float shortDashLength;
float longDashLength;

void setup() {
  noCursor();
  size(720, 720, P3D);
  //fullScreen(P3D);
  frameRate(60);

  textSize(50);
  //shortDashLength = 35;
  //longDashLength = 45;

  prevSecond = second();
}

void draw() {
  
  strokeWeight(1);
  shortDashLength = map(noise(seed),0,1,15,65);
  longDashLength = map(noise(seed+100),0,1,5,150);
  seed += 0.001;
  

  if (second()!=prevSecond) {
    secondMillis = 0;
    prevSecond = second();
  } else {
    secondMillis += millis() - prevSecondMillis;
    prevSecondMillis = millis();
  }

  if (minute()!=prevMinute) {
    minuteMillis = 0;
    prevMinute = minute();
  } else {
    minuteMillis += millis() - prevMinuteMillis;
    prevMinuteMillis = millis();
  }

  if (hour()!=prevHour) {
    hourMillis = 0;
    prevHour = hour();
  } else {
    hourMillis += millis() - prevHourMillis;
    prevHourMillis = millis();
  }

  s = map(second(), 0, 60, 0, TWO_PI);
  s += map(secondMillis, 0, 1000, 0, TWO_PI/60);

  m = map(minute(), 0, 60, 0, TWO_PI);
  m += map(minuteMillis, 0, 60000, 0, TWO_PI/60);
  //m += TWO_PI/60;

  h = map(hour(), 0, 12, 0, TWO_PI);
  h += map(hourMillis, 0, 60000*12, 0, TWO_PI/60);
  //h -= TWO_PI/12*2;

  background(0);
  stroke(255);

  drawDots();
  drawDashes();

  strokeWeight(1);

  pushMatrix();
  translate (width/2, height/2);
  rotate(s);
  line(0, 0, 0, (-height/2)+33);
  popMatrix();

  strokeWeight(2);

  //minute

  pushMatrix();
  translate (width/2, height/2);
  rotate(m);
  line(0, 0, 0, -height/2 + 33);
  popMatrix();

  //hour

  pushMatrix();
  translate (width/2, height/2);
  rotate(h);
  line(0, 0, 0, -height/4);
  popMatrix();

  //text

  //pushMatrix();

  //translate (width/2, height/2);
  //text(second(), 0, 0);
  //text(minuteMillis, 0, 50);
  //popMatrix();
}

void drawDots() {

  noFill();
  pushMatrix();
  translate (width/2, height/2);
  for (int i = 0; i <12; i++) {

    rotate(TWO_PI / 12);
    //circle(height/2-30, 0, 10);
    //line(height/4, 0,height/4-10, 0);
  }
  popMatrix();
}

void drawDashes() {

  pushMatrix();
  translate (width/2, height/2);
  //rotate(-TWO_PI/12*2);
  rotate(-TWO_PI/60);
  for (int i = 0; i <60; i++) {

    rotate((TWO_PI / 60));
    if (i%5==0) {
      //println(i);
      line(height/2-longDashLength, 0, height/2-30, 0);
    } else {
      line(height/2-shortDashLength, 0, height/2-30, 0);
    }
  }
  popMatrix();
}

```
