# How to create a Decisecond(0.1second) function that can use in the code?

I create a circular object and pivot the minute and second pointer on the middle of the object as below. Below is the code I use.

using System;
using UnityEngine;

public class Pivot_minute : MonoBehaviour
{
long x;

void Update()
{ //1complete revolution for minute pointer=3600000millisecond
x = DateTime.Now.Minute*60*1000+DateTime.Now.Second*1000+DateTime.Now.Millisecond;
transform.eulerAngles = new Vector3(0, 0, -(x*0.0001f));

}
}

using System;
using UnityEngine;

public class Pivot_second : MonoBehaviour
{
long x;

void Update()
{// 1 complete revolution for second pointer=60000millisecond,then x millisecond=x/60000*360degree
x = (DateTime.Now.Second*1000+DateTime.Now.Millisecond);
transform.eulerAngles = new Vector3(0, 0, -x*0.006f);
}
}


As tested, taking the millisecond precision is definitely showing a smoother pointer movement(not discrete movement) compare to the code below using "second" accuracy as calculation.

using System;
using UnityEngine;

public class Pivot_second : MonoBehaviour
{
int x;

void Update()
{// 1 complete revolution for second pointer=60 second, then x second= x/60*360 degree
x = (DateTime.Now.Second);
transform.eulerAngles = new Vector3(0, 0, -x*6);

}
}


Now I want to test the Decisecond(0.1second) accuracy to find out at this precision, can I still distinguish between the discrete movement and continuous movement of the pointer? Search through internet and so far do not have any luck.

• A decisecond is just 100 milliseconds. Presumably you tried taking your millisecond code and dividing x by 100? Jan 16 '21 at 17:19
• My mistake, suppose to say that how to produce a code that have the precision in between second and 100 milliseconds, example 500 milliseconds? The rotation is showing discrete movement in second but how about 500,600 millisecond and etc. Jan 17 '21 at 2:10
• So you tried dividing by 500, 600, etc? Jan 17 '21 at 2:13
• No. Sorry I do not understand how that going to help or even how to do that? As an example,DateTime.Now.Second output 1 second changes for every second, so at time=1.2second, it still output 1 second,1.3second also output as 1 second, only at time=2second, it output 2. so the resolution is 1 second and just I convert this resolution to rotational resolution. While I was hoping to find a code like "DateTime.Now.HalfMilliSecond" that change every 500millisecond. Jan 17 '21 at 3:19
• I see, you mean round up to the required decimal place in each step? I think I can try that out later. Thank for the idea. Jan 17 '21 at 3:24

using System;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
long y;
long x;
long z;
void Update()
{
y = DateTime.Now.Millisecond;
if(y<500)
{
x = 0;
}

if(y>500&&y<999)
{
x = 500;
}

z = (DateTime.Now.Second * 1000 + x);
transform.eulerAngles = new Vector3(0, 0, -z * 0.006f);
}


}

Thank for the idea, got it already just define the roundup boundary using if statement, then can define any precision I want in between second and millisecond.