- Home /
How can I have timespan display less
Currently when using
System.DateTime.Now.TimeOfDay
It will display 4 decimals:
Hours:Minutes:Seconds:TT
How can I make it display only 3 Hours:Minutes:Seconds?
Like a normal clock?
Answer by Baste · Sep 17, 2014 at 01:16 PM
You just split off the milliseconds. Try this:
string time = System.DateTime.Now.TimeOfDay.ToString().Split('.')[0];
Debug.Log(time);
Answer by Adamcbrz · Sep 17, 2014 at 01:13 PM
Based on the documentation here http://msdn.microsoft.com/en-us/library/System.DateTime_methods(v=vs.110).aspx you need to use the ToString Method and pass the format you want.
System.DataTime.Now.ToString("h:mm");
Thanks for the answer, I don't quite understand what's going on and it doesn't quite work, Baste's answer did the job but I will look further into this.
Thanks for the help.
Your answer
Follow this Question
Related Questions
How Would I Change This To Read Within A Time Range? 1 Answer
Smaller Time Interval? 3 Answers
javascript System time and date? 3 Answers
Unity3d School 1 Answer
Can I detect when the iOS system clock has been changed 0 Answers