- Home /
Timespan to int total seconds
Help please friends. In the post @Default117 resolve the cuestion, but i need convert the resul to int, the post is: http://answers.unity.com/answers/171314/view.html In this post the result of a time difference is obtained using a Timespan of the last time the time was saved when leaving and the start of the game, the result is a time in Timespan, I need to convert that result of the time difference in the number of total seconds in int. How can I make that conversion?
Answer by JVene · Aug 18, 2018 at 06:10 PM
Referencing Microsoft's documentation of TimeSpan, this illustrates what you can do:
TimeSpan i = new TimeSpan( 0, 0, 30, 25, 10 );
double s= i.TotalSeconds;
int n = (int) s;
int n2 = (int) ( s + 0.5 );
The second option suggests you could round the value to incorporate the fractional seconds appropriately, rather than truncate (the first example), or you can use Mathf.Round, or other means to round the double before casting it to an int.
Your answer
Follow this Question
Related Questions
convert 16bit float to 16bit int? 3 Answers
Converting a string into int is rounding off 1 Answer
Why Won't This Work? 1 Answer
ByteArray impossible to convert... ? 1 Answer
Download a WWW int? Or convert? 1 Answer