- Home /
Question by
DrProgrammer · Jan 24, 2011 at 06:36 AM ·
timefloatconvertdate
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?
Comment
Best Answer
Answer by yoyo · Jan 24, 2011 at 06:58 PM
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.
I thought i'll never get the answer. Thanks, that works.
Your answer
Follow this Question
Related Questions
How to convert 00:40:00.0 to float 2 Answers
How to compare two dates? 1 Answer
Unity Convert more int to one float or String and back? 1 Answer
Changing a float number by time 1 Answer
Get System date 1 Answer