Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by honjiepin · Aug 08, 2016 at 02:54 PM · c#time

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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)));

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image honjiepin · Aug 09, 2016 at 10:48 AM 0
Share

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.

avatar image Landern honjiepin · Aug 09, 2016 at 01:10 PM 0
Share

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:

LinqPAD TimeSpan Formatting

Working in Unity with DateTime Parse as the timespan format wouldn't function:

Working DateTime Parse

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image honjiepin · Aug 09, 2016 at 02:04 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

215 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges