Get time of AudioSource.Clip to System.Date format

Hi everyone.

I need to output AudioSource.Clip.time in format hh:mm:ss, but it's in a float format.

and even if i do this:

var hour = Mathf.Round((speakers[speakers.length-1].time/360));//speakers - is an array of AudioSource
var minutes = (speakers[speakers.length-1].time/60);
var sec = Mathf.Round((speakers[speakers.length-1].time));

Variable sec can be more than 60.

So how can i convert AudioSource.Clip.time to date format?

You can simply use the System.DateTime structure, like this:

var date : System.DateTime;
date = new System.DateTime(seconds * System.TimeSpan.TicksPerSecond);

If you want it as a nicely formatted string, use date.ToString(). This can also take a format parameter to control the formatting details, see MSDN docs for more info.