How to convert 00:40:00.0 to float

How can I convert time ( 00:40:00.0 ) to float. because I want to get the average of the time listed on my leaderboard.
ex.

00:20:12.0

00:34:12.0

01:32:12.4

05:12:33.5

12:23:12.1

I want to get the float equivalent of those time and average it.

2 Answers

2

Time.time is already a float. Don’t you want the opposite conversion?

int totalSeconds = parseInt(time);
int seconds = totalSeconds % 60;
int minutes = (totalSeconds/60) % 60;
int hours = (totalSeconds/3600);

float hundredths = time - totalSeconds;

oh sorry, 00:40:00.0 is string and I want to convert it to float so that I can get the average. btw, how can I get 00:40:50.0 out of "1. 00:40:50.0 - Name" ?

Check this out. It should be what you’re looking for.

String.Split(Char)

string time = "00:20:12.0"
    
string[] times = String.Split(':','.')

//You may have to parse the string to an int before assigning them
int hours = times[0]; //0
int minutes = times[1]; //20
int seconds = times[2]; //12
int milliseconds = times[3]; //0