C# Time.time Hours?
(int)Time.time % 60; gives me seconds and (int)Time.time / 60; gives me minutes. What is the equivalent for hours?
(int)Time.time % 60;
(int)Time.time / 60;
Answer by Bunny83 · Nov 21, 2015 at 05:42 AM
Of course to get hours you just need to use 3600 (60*60). Btw in your case you get absolute minutes. So for example if you run the game for two hours and 30 minutes Time.time/60 returns "150".
If you need days, hours, minutes, seconds It's easier to do it in seperate steps:
float t = Time.time;
int sec = (int)(t%60);
t /= 60;
int minutes = (int)(t%60)
t /= 60;
int hours = (int)(t%24)
t /= 24;
int days = (int)t;
edit Here's an example with direct values:
float t = Time.time;
int sec = (int)(t%60);
int minutes = (int)((t/60)%60)
int hours = (int)((t/3600)%24)
int days = (int)(t/86400); // There are 86400 seconds in a day (60*60*24)
Your answer
Follow this Question
Related Questions
How to make hundrenths of seconds in C#? 1 Answer
Can I AddClip() to Animation component during GameLoop? 0 Answers
Unity 5.3.5f1 personal + Visual Code 1.3.1 Code Suggestion 1 Answer
How can I autofire a ships gun every half second C# 1 Answer
FBX model loaded from AssetBundle not visible but is there. 1 Answer