- Home /
How to using date time?
using UnityEngine; using System.Collections; using System; public class controller : MonoBehaviour {
DateTime starttime;
DateTime life;
DateTime nowtime;
void Start () {
starttime = System.DateTime.Now;
life = starttime.AddSeconds (3);
}
void Update () {
nowtime = DateTime.Now;
if (nowtime == life){
Debug.Log ("wow");
}
}
}
Why 3seconds after dont run the "wow" message?
Answer by whydoidoit · Mar 09, 2014 at 11:31 AM
You can't be sure it will be exactly equal as it's really a time in milliseconds. Instead you need to check whether it is >= and then disable your check when the time has been exceeded.
Ah I knew $$anonymous$$rs Beacon's Typing Tutor would come in handy one day!
Answer by GameVortex · Mar 09, 2014 at 11:32 AM
Because of floating point precision the times will never be exactly equal. You should check if nowtime is more than life instead.
Your answer
![](https://koobas.hobune.stream/wayback/20220613135803im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
C# DateTime inspector 2 Answers
Date field for UI inputfield? 0 Answers
How to save DateTime in a list 1 Answer
Check How Many Minutes Have Passed 1 Answer
Percentage between DateTime 1 Answer