TimeUtil.cs 581 B

1234567891011121314151617181920212223242526
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class TimeUtil
  5. {
  6. //格式化,最终得出分和秒
  7. public static string GetTimeStr(float time, bool ceil = true)
  8. {
  9. int seconds = ceil ? Mathf.CeilToInt(time) : Mathf.FloorToInt(time);
  10. string str = "";
  11. int m = seconds / 60;
  12. if (m < 10) {
  13. str += 0;
  14. }
  15. str += m;
  16. str += " : ";
  17. int s = seconds % 60;
  18. if (s < 10)
  19. {
  20. str += 0;
  21. }
  22. str += s;
  23. return str;
  24. }
  25. }