how to display stopwatch ss\fff as string?
hi, i hope theres a good person out there not like before suddenly close my question without help. please be nice with noob. im using this code to show time for my stopwatch
void OnGUI() {
GUILayout.Label (System.TimeSpan.FromSeconds (Time.time).ToString ());
it show right with no problem with format hh\mm\ss\fff but what i want is i want to show only second and millisecond. example, 72 second 129 millisecond, actually will show as 72.129 but i want it to be 72129 but i dont have idea how to get it.
i already check in https://msdn.microsoft.com/en-us/library/ee372287(v=vs.110) but i dont get what i want. please help
Answer by Landern · Aug 08, 2016 at 05:25 PM
Adjust as needed
void OnGUI() {
GUILayout.Label (string.Format("{0:ss} seconds {0:fff} milliseconds", System.TimeSpan.FromSeconds (Time.time)));
sir, your code still show same as $$anonymous$$e one that is xx:xx:xx.xxxxxxxxx millisecond. still can't get like what i need without showing hours and $$anonymous$$utes.. do i miss something sir? thank you for your answer. or do you think i use math such as add 1 in every millisecond (realtime add)ins$$anonymous$$d of using time? but i dont know how to start.
It would appear my tests in LinqPAD didn't translate over to Unity.
Here is a working solution:
GUILayout.Label (string.Format("{0:ss} seconds {0:fff} milliseconds", System.DateTime.Parse(System.TimeSpan.FromSeconds (Time.time).ToString())));
LInqPAD showed formatting fine with my original post above, but didn't work in unity:
Working in Unity with DateTime Parse as the timespan format wouldn't function:
Answer by Gaffail · Aug 08, 2016 at 04:06 PM
Not too familiar with TimeSpan, but you could just use Mathf.Round(Time.time * 1000F).ToString (). It will give you 72129 instead of 72.129.
hi sir, thx for your answer. but i still can't get from your code. but i am thinking about im using math to add 1 in every millisecond (real time clocking) ins$$anonymous$$d using time. i mean, in every 1 millisecond will add 1 and it will run as a timer also, what do you think? but i don't know how to start. can you help please?
Your answer
Follow this Question
Related Questions
Wait time after coroutine's wait seconds is complete 0 Answers
GAME - profit simulating after game is close - ANDROID 0 Answers
UnityEngine.Invoke() Doesn't work properly with values under 1? 0 Answers
how to save time and take the next variable in enum? 1 Answer
why does timescale not work? 2 Answers